in reply to Count file lines in a directory tree
my $root = rel2abs (shift || '.');
I wouldn't use rel2abs: if I give '.' as an argument, I expect it to be honored. Unless there were some specific option to explicitly instruct the program to do otherwise, that is.
my @extList = @ARGV; @extList = ('pl', 'pm') if ! exists $extList[0];
How 'bout
my @extList = @ARGV ? @ARGV : qw/pl pm/;
instead?
my $lines = 0; my $files = 0;
No need for the initializations. Maybe you want them anyway for (your) clarity. For me,
my ($lines, $files); # is clear enough
sub count { my $name = $File::Find::name; return if -d $name;
Maybe in this case you would prefer to use the no_chdir => 1 option to find() which seems more appropriate...
my ($ext) = $name =~ /\.([^.]*)$/; return if ! defined $ext or ! exists $exts{$ext};
How 'bout
return if grep $name =~ /\.\Q$_$/, @extList;
?
return if ! open inFile, '<', $name;
open my $in, '<', $name or # and I don't need close() (warn "Ouch: $name => $!\n"), return;
++$lines while (<inFile>);
Hmmm, I always recommend against slurping in whole files (if unnecessary), but perhaps
$lines+=<$in>;
...
|
|---|