#!/usr/bin/perl -- #~ #~ #~ #~ # perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use autodie; # error checking for open/close... Main( @ARGV ); exit( 0 ); sub Main { my( @files ) = @_; if( not @files ) { my $lines = q{ And "then" something "happened" on "the first and second and third lines" and then it was over}; @files = ( \'"the boat"', \$lines, \"$lines $lines $lines" ); } for my $file ( @files ) { print "## { $file }{ wordcount= ", Vote( $file ), " }\n"; } } ## end sub Main sub Vote { my( $fyle ) = @_; open my( $wyld ), '<:raw', $fyle; my $in_quotes = 0; my $words = 0; while( my $line = readline $wyld ) { pos( $line ) = 0; WORDCOUNTER: while( length( $line ) > pos( $line ) ) { $line =~ m{ \G\s*\x22 # quote after optional whitespace }gxcs and do { $in_quotes = !$in_quotes; ## flip it next WORDCOUNTER; }; $in_quotes and $line =~ m{ [^\x22\s]+ ## not quote or whitespace }gxcs and do { $words++; next WORDCOUNTER; }; $line =~ m{ \G[^\x22]+ ## not quote }gxcs and do { next WORDCOUNTER; }; } ## end of WORDCOUNTER } ## end of readline return $words; } ## end sub Vote __END__ ## { SCALAR(0xbb713c) }{ wordcount= 2 } ## { SCALAR(0xad05a4) }{ wordcount= 9 } ## { SCALAR(0x3f8fec) }{ wordcount= 27 }