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.) |