CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
filehandle directory path unix vs. windows

 



aasadourian
New User

Mar 15, 2007, 1:14 PM

Post #1 of 4 (1396 views)
filehandle directory path unix vs. windows Can't Post

Hello World Wink

I have a perl script that runs in unix and windows environment. I create a filehandle and populate it with data. In my script I chdir to the /unix/path where I want to save my data. But when I'm in windows and the script is called it does not know the /unix/path. I want the file to be written to this /unix/path no matter what OS i'm in. Does anyone have an idea of what I need to do to distinguish between unix and windows?

Thank you for your time,

aasadourian.


----sample code-----

#! /usr/bin/perl

########## Variables #######

$ACTION_DATE = localtime;

$MACHINE = `hostname`;

$OP_KIND = "$ENV{'CLEARCASE_OP_KIND'}";
$USER = "$ENV{'CLEARCASE_USER'}";
$ELEMENT_NAME = "$ENV{'CLEARCASE_PN'}";
$ELEMENT = "$ENV{'CLEARCASE_XPN'}";

#############################

$logFile = "trgCOLog";

if (($OP_KIND eq "checkout") || ($OP_KIND eq "checkin")) {
print "Inside $OP_KIND loop\n" if ( $debug );
chdir("/home/adm/temp") || die "Can't move to /home/adm/temp, error: $!\n";
open(LOG, ">> $logFile") || die $!;
print "File exists...\n" if ( $debug );
# write output to a file
print LOG "*****************\n";
print LOG "NEW CO/CI EVENT\n";
print LOG "Element: $ELEMENT\n";
print LOG "Element Name: $ELEMENT_NAME\n";
print LOG "Performed By: $USER\n";
print LOG "Machine: $MACHINE";
print LOG "Date: $ACTION_DATE\n";
close(LOG) || die "Can't close: $!";
} # end of co/ci
exit 0;


(This post was edited by aasadourian on Mar 16, 2007, 9:02 AM)


KevinR
Veteran


Mar 15, 2007, 3:40 PM

Post #2 of 4 (1395 views)
Re: [aasadourian] filehandle directory path unix vs. windows [In reply to] Can't Post

nothing really, windows doesn't care if you use forward or backwards slashes in directory paths. So 'path/to/folder' will work with windows no problem.
-------------------------------------------------


davorg
Thaumaturge / Moderator

Mar 23, 2007, 9:08 AM

Post #3 of 4 (1373 views)
Re: [aasadourian] filehandle directory path unix vs. windows [In reply to] Can't Post

As KevinR says, Windows should handle the Unix forward slashes without any problems.

But if you really need to know what operating system you are running on then take a look at the contents of the $^O variable.

Update: KevinR is right. I'm getting my slashes confused. Corrected.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


(This post was edited by davorg on Mar 23, 2007, 9:54 AM)


KevinR
Veteran


Mar 23, 2007, 9:47 AM

Post #4 of 4 (1371 views)
Re: [davorg] filehandle directory path unix vs. windows [In reply to] Can't Post

Windows should handle the Unix forwardslashes without any problems. Wink
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives