Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re^3: Samples of big projects done in Perl by hv
in thread Samples of big projects done in Perl by techcode

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found