note
hv
<p><i>Has anyone written a line counter with POD sections stripped out?</i></p>
<p>Here's the somewhat rough-and-ready code I use to count lines in my work application:<c>
#!/usr/bin/perl -w
use strict;
use File::Find;
my($d, $c, $h, $q, $s, $x) = (0, 0, 0, 0, 0, 0);
for my $dir (qw/ cgi lib util /) {
find(sub {
return if /^\.#/ || /,v$/ || /\.(swp|gif|jpg|png|ps|tr|o|a)$/ || /~$/ || /^core$/;
$File::Find::prune = 1, return if $File::Find::dir =~ /\bCVS\b/;
return unless -f && -T;
local *F;
my $file = $_;
open F, $file or warn "$File::Find::dir/$file: $!\n";
my $cut = 0;
my $here = undef;
my $where;
while (<F>) {
if ($cut) {
++$$where;
$cut = 0 if $cut > 0 && /^=cut/;
} elsif ($here) {
++$$where;
$here = undef if /$here/;
} elsif (/^=/) {
++$d;
$cut = 1;
$where = \$d;
} elsif (!/\S/) {
++$s;
} elsif (/^\s*#/) {
++$c;
} elsif (/<<(?:'(\w+)'|(\w+))/) {
my $style = $1 || $2;
$where = ($style eq 'SQL') ? \$q : \$h;
$here = qr/^$style$/;
++$x;
} elsif (/^__(DATA|END)__$/) {
$cut = -1;
$where = \$h;
} else {
++$x;
}
}
}, $dir);
}
print "doc $d, comment $c, SQL $q, text $h, space $s, code $x\n";
</c></p>
<p>This currently reports: doc 5699, comment 1685, SQL 675, text 4295, space 4382, code 37030.</p>
<p>Hugo</p>
565877
565949