in reply to Count Quoted Words

Unless the words array is also needed for something else, my preferred solution would be to skip it entirely and just use a regex on the whole file content (what can I say, I like regexes):
use File::Slurp; my $text = read_file('input.txt'); while ($text =~ /" (.*?) "/sg) { print "Found quoted string with ".split(' ', $1)." words: $1\n"; }
The regex might need to be adjusted depending on the exact definition of what should be counted as a quoted string within the input data.

Replies are listed 'Best First'.
Re^2: Count Quoted Words
by flash4syth (Initiate) on Jun 13, 2013 at 03:35 UTC

    Thanks! I ended up going with this solution as it is easy to read and allows me to get other data about the entire text using regex's.