Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Count Quoted Words

by Cristoforo (Deacon)
on Jun 07, 2013 at 02:10 UTC ( #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


Comment on Re: Count Quoted Words
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2014-09-17 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (72 votes), past polls