Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: problem in substitution

by rminner (Chaplain)
on Dec 08, 2008 at 13:16 UTC ( [id://728934]=note: print w/replies, xml ) Need Help??


in reply to problem in substitution

Just like poolpi said, File::Spec is the way to go. Substituting a directory segment of a path can be annoying, because paths tend to be specified in different formats. For example: File::Find under windows returns the results with a slash appended, even though the path was specified using backslashes. In such cases you have a mixed syntax of slashes and backslashes. If you use File::Spec, you won't have to worry about the specific syntax of a path. Example:
use File::Spec; # Example with mixed syntax my $old_dir = "D:\\Windows\\programs1"; my $new_dir = "D:\\Windows/programs2"; my $old_fn = "D:/Windows/programs1/a.txt"; my $rel_path = File::Spec->abs2rel($old_fn, $old_dir); my $new_fn = File::Spec->catfile($new_dir , $rel_path); print "New Filename: $new_fn\n"; # or combine both: my $new_fn2 = File::Spec->catfile($new_dir , File::Spec->abs2rel($old_ +fn, $old_dir)); print "New Filename2: $new_fn2\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-23 21:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found