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)";