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

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

( #53601=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > How do I change .. to the real filename? 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; }

Comment on Answer: How do I change .. to the real filename?
Download Code
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-07-23 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (137 votes), past polls