Also look into using File::Spec module for platform independent file manipulation. Much easier to use than doing it yourself in your code.
Or using the glob() method instead of spawning calls to dir or ls. There are usually modules you can download to avoid having to test $^O settings and spawn platform dependant tasks to hide the mess. As to windows, you have to associate the ".pl" extension with the "perl.exe" executable so it will automatically run. It doesn't care about the 1st line of the file like Unix does, windows is file extension based. So by default I always put in #!/usr/bin/perl at the start of every perl program, even on windows. Also if you put a perl program in a scheduled task that requires command line arguments, you will need to do "perl prog.pl -a -b -c", but if it doesn't take arguments, you can just do "prog.pl" once the association is made. Curtis ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Campbell, Scott Sent: Thursday, January 24, 2008 1:21 PM To: Gary Yang; [email protected] Subject: RE: Questions on porting Perl from Windows to Unix $^O if($^O!~m/Win32/){ #This is NOT Windows } else{ #This is Windows } ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gary Yang Sent: Thursday, January 24, 2008 2:17 PM To: [email protected] Subject: Questions on porting Perl from Windows to Unix Hi All, I need to port my Perl script from Unix to Windows. Can someone tell me how to figure out which platform I am on? i.e. I need to know which Perl command can help me determin the platform. Once I know the platform, I'll code my script as the example bellow. But, how to figure out I am on Windows or Unix? if ($usingUNIX) { $directory = `ls`; #UNIX version. $copyCommand = `cp`; #UNIX version. } else { $directory = `dir`; #Win32 version. $copyCommand = `COPY`; #Win32 version. } Second question: The UNIX #!/usr/bin/perl notation does not work with Perl scripts on Windows. How should I code if it is Unix I place "#!/usr/bin/perl" at the very first line of the script? But, I do not place it at the first line of code if it is not Unix? How should I do it? Your answers are greatly appreciated. Thanks, Gary ________________________________ Never miss a thing. Make Yahoo your homepage. <http://us.rd.yahoo.com/evt=51438/*http:/www.yahoo.com/r/hs> _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
