Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2016-06-27 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (337 votes). Check out past polls.