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

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.

Comment on Re: Regular expression parse pathname
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2015-12-01 01:54 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (791 votes), past polls