use strict; use warnings; use File::Find; use Cwd; our $dir = shift || cwd(); our @types = ('pl', 'plex', 'pm'); our @files; find sub { return unless -f; my $fName = $_; foreach (@types) { my (undef, $ext) = split (/\./, $fName); $ext and push @files, $File::Find::name if $ext eq $_; } }, $dir; unless (@files) { die "No files found to operate on!"; } print(" Code Cmts %Code Total File \n"); print "=" x 80 . "\n"; my ($TLOC, $TCOM, $TTOT) = (0,0,0); foreach my $file (@files) { my ($LOC, $COM) = (0,0); my $contents = do { local (*ARGV, $/) = [$file] and <> }; my @lines = grep { ! /^\s*$/ } split(/$\//, $contents); while (@lines) { $_ = shift @lines; if ( /^=[a-z0-9]+\s/ ) { do { $_ = shift @lines and $COM++; } until /^=cut/; } /^\s*\#/ ? undef $_ || $COM++ : $LOC++; } my $TOT = $LOC + $COM; $TLOC += $LOC; $TCOM += $COM; $TTOT += $TOT; my $PER = sprintf("%3s", sprintf("%.0f", ($COM/$TOT) * 100)); printf("% 6d % 6d % 6d % 6d %s\n", $LOC, $COM, $PER, $TOT, ' '. substr $file, length($dir)); } my $TPER = sprintf "%.2f", ($TCOM/$TTOT) * 100; print "=" x 80 . "\n"; print "SEARCHD: '$dir'\n"; print "RESULTS: $TLOC LoC ($TTOT w/comments: $TCOM lines -> $TPER% of +total)";

In reply to Perl project lines of code "analyzer" by psychotic

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.