Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Alternative for a directory builder

by Eliya (Vicar)
on Feb 22, 2011 at 18:50 UTC ( #889655=note: print w/replies, xml ) Need Help??

in reply to Alternative for a directory builder

If the order doesn't matter, you could sucessively chop off stuff from the end.  This prints the same as your code, but reversed:

my $_=$a; say while s|[^/]+/*$||; __END__ /aaaa/bbbb/cccc/dddd/ /aaaa/bbbb/cccc/ /aaaa/bbbb/ /aaaa/ /

But if order does matter (e.g. for mkdir purposes), you can of course also say

my @dirs; my $_=$a; push @dirs, $_ while s|[^/]+/*$||; say for reverse @dirs; __END__ / /aaaa/ /aaaa/bbbb/ /aaaa/bbbb/cccc/ /aaaa/bbbb/cccc/dddd/

Replies are listed 'Best First'.
Re^2: Alternative for a directory builder
by cyber-guard (Acolyte) on Feb 22, 2011 at 19:39 UTC
    This is really really sweet solution! Thanks a LOT. Might actually use it instead of my current code:)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://889655]
[robby_dobby]: marto: Good morning, I usually spend my Fridays here cursing the bloody weather!
[marto]: where are you based robby_dobby?
[robby_dobby]: marto: Oh, I see you're from an even colder north :-)
[robby_dobby]: marto: Ldn, right now
[marto]: icy here today, snow on the hills

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-12-15 10:28 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (430 votes). Check out past polls.