Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Regular expression parse pathname

by rubasov (Friar)
on Jan 29, 2010 at 02:38 UTC ( #820289=note: print w/replies, xml ) Need Help??


in reply to Regular expression parse pathname

Try this:
echo "/home/code/work" |\ perl -nle 'chomp; print $p .= $& while m{ \G (?: [^/]* /+ | [^/]+ \z ) + }xg'
The m/\G.../g match can be called several times, and each time it will start at the position where last time it left off.

However be aware, that this one-liner produces a little different tree than your example, but probably you want to represent the real file system tree and this result is a better representation of it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://820289]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2016-12-10 15:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (163 votes). Check out past polls.