While 99.999% of Perl is completely portable between the various platform implementations (Unix, Win32, Mac, etc), there are a few gimmes and gotchas that always seem to crop up in
your application. I've been keeping a running tally in my head, but figured that I should write them down, seeing as a number of posts in the past two months have ended up centering on these issues.
If you know of any that aren't listed here, please either msg me or reply and I'll update. Also, if I've got something wrong or incomplete, tell me as well.
- The biggest one that trips people up is newlines. On Unix, a newline is a \n. On Win32, it's \r\n, and on Mac it's \r. chomp will only use what's in your $\ variable, so if you're on Unix and reading from a file FTP'ed from a Win32 machine, you'll miss the \r. To fix this, do the following:
my $line = <SOME_FILE>;
chomp($line);
$line =~ s/\r$//;
- On Unix, select will check STDIN and STDOUT, as implied by the perldoc. On Win32, it will not.
- Let's say a SIG_INT signal triggers some handler. The handler doesn't do anything and simply ends, returning execution back to where it was before. If another SIG_INT is triggered, Unix will handle it by calling the handler again and Win32 will simply die. (Does this mean that Win32 requires the SIG_INT handler to be re-set?)
- Win32 requires that binmode is called before writing binary data files. Unix does not. (submitted by grinder)
- Be careful with case-sensitivity. Unix is case-sensitive, but Other OS'es may not be, such as DOS and Win32. (Win32 remembers capitalization, but A.txt and a.txt aren't allowed in the same directory.) (submitted by arhuman)
- Be careful with meta-characters in your filenames. Unix and Win32 both accept spaces in their filenames. DOS (for example) does not. Unix accepts most metacharacters, like -$#@^, etc. Win32 may or may not. Other filesystems most definitely will not.
- Certain filenames may or may not cause troubles. These include CON, PRN, AUX, and the like. (submitted by arhuman)
Update: Given that
arhuman kindly pointed out
perlman:perlport and
perlman:perlport2, I'll point people there as well.
perlman:perlport is a discussion of the broad differences between the various platforms and
perlman:perlport2 is a (rather terse and unenlightening) discussion of the various functions and how they're implemented (or not) on said platforms. I do think that a discusion of just
what the differences mean to a given programmer is important.
For example, perlman:perlport2 says that select is implemented only on sockets in Win32. What does that mean to you? Why would you want to select on non-sockets? That's what this Meditation was meant to be about.
Update2: agent00013 remarked that Win32 is not case-sensitive.
------
/me wants to be the brightest bulb in the chandelier!