in reply to Cross platform compatability Part 1: Shells and Files

It irritates me, jepri, that you make a big deal of being cross platform compatible and offer alternatives for standard unix perlisms (with a few errors), and yet

I am actually currently involved in making cross-platform code and would be interested to know more about making things more windows and mac-friendly.

one last note:

open (FH, ">/temp/tempfile"); print FH $temporary_data;
I dont think I've ever worked on a *nix system that had a /temp directory. The Unix System Administration Handbook (3rd ed) doesnt mention it, either. You're looking for /tmp.

dep.

--
i am not cool enough to have a signature.

Replies are listed 'Best First'.
Re: Re: Cross platform compatability Part 1: Shells and Files
by chipmunk (Parson) on Jan 21, 2001 at 22:36 UTC
    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.)