Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2016-10-21 15:15 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.