Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Count Quoted Words

by smls (Friar)
on Jun 07, 2013 at 04:14 UTC ( #1037569=note: print w/replies, xml ) Need Help??

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2021-04-23 16:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found