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:
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.if (-f $_) { if (-s _ == 0) { print $File::Find::name, "\n"; } }
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}, ...);
In reply to Re: function help
by pc88mxer
in thread function help
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |