Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: rel2abs doesn't resolve relative paths?

by Oberon (Monk)
on Jun 07, 2003 at 01:17 UTC ( [id://263897]=note: print w/replies, xml ) Need Help??


in reply to rel2abs doesn't resolve relative paths?

> ... are there any standard functions that would return "/home/bob" or will I have to write my own subroutine to get rid of the ..'s?

My solution to this problem has been to grab File::VirtualPath. It's not standard, but at least you wouldn't have to write your own ...

# warning! untested code ahead use File::VirtualPath; my $p = File::VirtualPath->new(); $p->path("/home/myuser"); # or use cwd() $p->chdir("../bob/"); print $p->path_string(); # should yield /home/bob

And of course you could wrap all that up in a sub if you like. I like this particular solution because it works even if you're referring to a path that doesn't exist (maybe it doesn't exist yet, but it will, or it's a path to something other than a physical file in the file system).

HTH.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found