Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Samples of big projects done in Perl

by hv (Prior)
on Aug 08, 2006 at 10:32 UTC ( [id://566118]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Samples of big projects done in Perl
in thread Samples of big projects done in Perl

Has anyone written a line counter with POD sections stripped out?

Here's the somewhat rough-and-ready code I use to count lines in my work application:

#!/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";

This currently reports: doc 5699, comment 1685, SQL 675, text 4295, space 4382, code 37030.

Hugo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://566118]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-03-19 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found