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}, ...);