I'm curious to know what MacPerl does whether it converts file/path/ to file:path: or it actually needs colons.

MacPerl does not convert 'file/path/' to 'file:path:'; one must actually use colons in the paths.

Even trickier, however, is the way of specifying relative paths, by prepending the directory separator. On a Mac, ':mammal:dog' means the file dog in the directory mammal in the current working directory, whereas on Unix '/mammal/dog' means the file dog in the directory mammal in the root directory.

On the other hand, the path 'animal:mammal:dog' on a Mac means the file dog in the directory mammal in the root directory of the volume animal. On Unix 'animal/mammal/dog' means the file 'dog' in the directory 'mammal' in the directory 'animal' in the current working directory.

Here's a script that demonstrates this behavior in MacPerl:

use Cwd; print cwd(), "\n"; -e 'foo' or mkdir('foo', 0777) or die "Can't mkdir 'foo': $!\n"; open(FH, '>foo/bar') or warn "Can't open 'foo/bar': $!\n"; # creates a file named 'foo/bar' in cwd open(FH, '>foo:bar') or warn "Can't open 'foo:bar': $!\n"; # fails, unless you actually have a volume named 'foo' # in that case, creates a file named 'bar' on the volume 'foo' open(FH, '>:foo:bar') or warn "Can't open ':foo:bar': $!\n"; # creates a file named 'bar' in the directory 'foo' in the cwd

Getting cross-platform file paths is not an easy problem. That's why the File::Spec module was created. (Except that all the documentation for the module is in File::Spec::Unix. You'll have to read it locally.)


In reply to Re: Re: Cross platform compatability Part 1: Shells and Files by chipmunk
in thread Cross platform compatability Part 1: Shells and Files by jepri

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.