Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: How to Get the Last Subdirectories

by sigma8 (Initiate)
on Mar 11, 2010 at 22:55 UTC ( #828155=note: print w/replies, xml ) Need Help??

in reply to How to Get the Last Subdirectories

I don't think there is a way to do it inline in the File::Find subroutine without recursion, but if you can wait until the end, I think this should do it:

#!/usr/bin/perl use strict; use File::Find; my %seen; find( sub { if (-d) { $seen{$File::Find::name}++; delete $seen{$File:: +Find::dir} }; }, '/tmp/a' ); print join "\n", (keys %seen, undef);
This creates a hash key for every directory, and deletes every key that is the same name as the parent. Therefore directories who have no children will never get deleted.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2016-10-23 11:13 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (301 votes). Check out past polls.