Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Count Quoted Words

by Cristoforo (Curate)
on Jun 07, 2013 at 02:10 UTC ( [id://1037548]=note: print w/replies, xml ) Need Help??


in reply to Count Quoted Words

Here is an example, partly from the docs for Text::ParseWords, (part of core since perl 5). But, it is not using an array, but the whole body of text.
#!/usr/bin/perl use strict; use warnings; use Text::ParseWords; my $text; do {local $/; $text = <DATA>}; my @words = quotewords('\s+', 1,$text); my $i = 0; foreach (@words) { if (/^".+"$/s) { printf "<%s> : COUNT %d\n", $_, scalar split; } } __DATA__ "Yes, yes, how was it now?" he thought, going over his dream. "Now, how was it? To be sure! Alabin was giving a dinner at Darmstadt; no, not Darmstadt, but something American. Yes, but then, Darmstadt was in America. Yes, Alabin was giving a dinner on glass tables, and the tables sang, _Il mio tesoro_--not _Il mio tesoro_ though, but something better, and there were some sort of little decanters on the table, and they were women, too," he remembered.
The out put is:
C:\Old_Data\perlp>perl t33.pl <"Yes, yes, how was it now?"> : COUNT 6 <"Now, how was it? To be sure! Alabin was giving a dinner at Darmstadt; no, not Darmstadt, but something American. Yes, but then, Darmstadt was in America. Yes, Alabin was giving a dinner on glass tables, and the tables sang, _Il mio tesoro_--not _Il mio tesoro_ though, but something better, and there were some sort of little decanters on the table, and they were women, too,"> : COUNT 66

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-25 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found