Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Collapsing paths

by johngg (Canon)
on Dec 05, 2007 at 14:34 UTC ( [id://655097]=note: print w/replies, xml ) Need Help??


in reply to Collapsing paths

I have a module that includes this code ref. that you should be able to adapt to do what you want.

# ---------- my $_cleanPath = sub # ---------- { my $absPath = shift; return $absPath if $absPath =~ m{^/$}; my @elems = split m{/}, $absPath; my $ptr = 1; while( $ptr <= $#elems ) { if( $elems[ $ptr ] eq q{} ) { splice @elems, $ptr, 1; } elsif( $elems[ $ptr ] eq q{.} ) { splice @elems, $ptr, 1; } elsif( $elems[ $ptr ] eq q{..} ) { if( $ptr < 2 ) { splice @elems, $ptr, 1; } else { $ptr --; splice @elems, $ptr, 2; } } else { $ptr ++; } } return $#elems ? join q{/}, @elems : q{/}; };

I hope this is of use.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-29 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found