Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Count file lines in a directory tree

by blazar (Canon)
on Nov 10, 2005 at 13:23 UTC ( #507371=note: print w/replies, xml ) Need Help??

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/;


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



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://507371]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2018-06-18 18:23 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.