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.

  1. 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$//;
  2. On Unix, select will check STDIN and STDOUT, as implied by the perldoc. On Win32, it will not.
  3. 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?)
  4. Win32 requires that binmode is called before writing binary data files. Unix does not. (submitted by grinder)
  5. 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)
  6. 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.
  7. 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!


In reply to Platform Differences by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.