Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: function help

by pc88mxer (Vicar)
on Jun 03, 2008 at 16:51 UTC ( [id://689944]=note: print w/replies, xml ) Need Help??


in reply to function help

As others have said, don't call find within find - it's not reentrant.

Your first internal use of find can definitely be eliminated (since you're just calling find on a file) and replaced with the following simpler code:

if (-f $_) { if (-s _ == 0) { print $File::Find::name, "\n"; } }
For directories it appears you want to visit the directory twice - once when it is encountered and later when File::Find is done with all of its entries. To do this, look up the documentation on the postprocess option. It specifically says it is useful for summarizing a directory, such as calculating its disk usage.

Not tested, but should illustrate the idea:

my %usage; sub wanted { if (-f $_) { my $size = -s _; $usage{$File::Find::dir} += $size; if ($size == 0) { print $File::Find::name, "\n"; } } } sub postprocess { print "Usage of $File::Find::dir is $usage{$File::Find::dir}\n"; } find({wanted => \&wanted, postprocess => \&postprocess}, ...);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-25 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found