Okay, since we’re all nitpicking, how about using a better file system iterator module? And some more gravvy?

#!/usr/bin/perl use strict; use warnings; =head1 NAME countln - recurse directories and counts lines in matching files =head1 SYNOPSIS F<countln> S<B<[ -e ext1,ext2 ]>> S<B<[ -r rootdir ]>> =head1 OPTIONS =over =item B<-e>, B<--ext> What extensions to match. Can be given multiple extensions separated b +y commata, and can be given multiple times. If none given, defaults t +o F<.pm> and F<.pl>. =item B<-r>, B<--root>, B<--dir> Which directory to start recursing in. Defaults to the current directo +ry =head1 SEE ALSO find(1), wc(1) =head1 BUGS None known. =head1 AUTHORS ... =head1 COPYRIGHT AND LICENCE ... =back =cut use Getopt::Long; use Pod::Usage; use File::Find::Rule; GetOptions( 'h|help' => sub { pod2usage( -verbose => 1 ) }, 'man' => sub { pod2usage( -verbose => 2 ) }, 'ext|e=s' => \( my @opt_ext ), 'root|dir|r=s' => \( my $opt_root = "." ), ) or pod2usage(); @opt_ext = @opt_ext ? map { split /,/ } @opt_ext : qw( pl pm ); my @file = File::Find::Rule ->file() ->name( map "*.$_", @opt_ext ) ->in( $opt_root ); my $lines = 0; for my $fname ( @file ) { open my $fh, '<', $fname or warn( "Couldn't open $fname: $!\n" ), next; local $/ = \131072; $lines += tr/\n// while <$fh>; $lines++ if not /\n\z/; } print "$lines lines in " . @file . " files\n";

Makeshifts last the longest.


In reply to Re: Count file lines in a directory tree by Aristotle
in thread Count file lines in a directory tree by GrandFather

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.