There isn't much you have to be aware of, but you may feel a little discomforted by having to give up some amazingly cool shell tricks. I think there are replacements for almost all of them.
and insist the the user run:while (<>) { do_stuff_to $_; } or for (@ARGV) { do_stuff_to $_; }
The shell (bash, sh, ksh, etc.) expands the * into the list of filenames and hands it to the your program. Unfortunatly DOS/Windows doesn't. You can't rely on the shell working correctly under *nix anyway. A system manager may decide to restrict scripts to running on some primitive shell for memory or security reasons. Use
See here for a nice example.while (<*>) { do_stuff_to $_; } or better opendir DH,"."; @dir=readdir DH; closedir DH; foreach (@dir) { Do_your_thing $_; }
open (FH, ">/temp/tempfile"); print FH $temporary_data;
DOS/Windows coders can get their revenge by using
open FH "C:\temp";
You shouldn't be using hard-coded parameters in your program anyway. It will bite you later when you realise you need the temporary file in a different place, and have to go trolling through your code to find all the places you hard-coded it. This is easily solved by placing:
my $tempdir = "/temp/"; my $tempfile = "tempfile"; and then open FH "$tempdir$tempfile";
Always finish your directory names with the directory symbol (forwards or backwards slash or whatever).
The ls -lR is a problem, because it does a directory recursion much more easily than File::Find. If you're doing a serious script though, you should be File::Find. There's even a wrapper for it now, so it's easier to use.
I hope these few examples have given you a bit of direction when it comes to making your scripts cross-platform. I'm not saying your three-line file parser should be platform independent, but if you're submitting a one-page program to the monastery it would be nice if the windows users could cut'n'paste it too.
____________________
Jeremy
I didn't believe in evil until I dated it.
|
|---|