Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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.

Comment on Re: How to Get the Last Subdirectories
Download Code

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 browsing the Monastery: (8)
As of 2015-12-01 08:18 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 (796 votes), past polls