Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: How to Get the Last Subdirectories

by rovf (Priest)
on Mar 12, 2010 at 09:04 UTC ( #828243=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to Get the Last Subdirectories
in thread How to Get the Last Subdirectories

You are basically interested in those directories in your tree which have no subdirectories; so the following algorithm should work:
  1. Initially create an empty hash %leaf_directories
  2. Whenever File::Find drops you into a directory $d, do the following:
    1. Remove the parent directory of $d from the hash, i.e. if $d contains the full path, do a delete $leaf_directories{dirname($d)}. Of course this will fail occasionally (because there is no corresponding entry), but we ignore this.
    2. Add $d to your hash, i.e. $leaf_directories{$d}=1
In the end, keys $leaf_directories should be the list of the directories without subdirectories.


-- 
Ronald Fischer <ynnor@mm.st>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://828243]
help
Chatterbox?
[Corion]: Meh, stupid people are associated with every president
[Corion]: (or presidential candidate)
[Corion]: And if you only have two candidates, you can expect some of the stupid people to make the "right" choice by chance ;)
[erix]: I think it's a little worse this time :)
[Discipulus]: yes; even broken clock show the right time twice a day

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-01-24 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (203 votes). Check out past polls.