Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Answer: How do I change .. to the real filename?

by dcardamo (Initiate)
on Jan 23, 2001 at 02:30 UTC ( #53601=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I change .. to the real filename? - Answer contributed by dcardamo

I tried the first solution, and it didn't work properly. I haven't tried the second, but here is a non-regex routine that I wrote to do that:
sub relpath($) { my $file = shift; my $newfile = ""; $file =~ s/\n//g; # remove new lines my @peices = split /\//, $file; for (my $i = 0; $i <= $#peices; $i++) { if ($peices[$i + 1] eq "..") { last; } if ($peices[$i] ne ".") { $newfile .= "/$peices[$i]"; } } $newfile =~ s/\/\//\//g; return $newfile; }

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-12-08 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (135 votes). Check out past polls.