sub countdir {
my $dir = shift @_;
my @files = < $dir >;
my $count = 0;
for my $file (@files) {
if (-d $file) {
$count += countdir("$file/*");
next;
}
open my $fd, '<', $file or die "cannot open file $file\n";
my @lines = <$fd>;
close $fd;
map { $count++ if ($_ !~ /^\s*$/) } @lines;
}
return $count;
}
print countdir('./*') . "\n";