Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Cross platform compatability Part 1: Shells and Files

by chipmunk (Parson)
on Jan 21, 2001 at 22:36 UTC ( [id://53357]=note: print w/replies, xml ) Need Help??


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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://53357]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found