Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
"be consistent"
 
PerlMonks  

Re: hash to count words

by tobyink (Abbot)
on Sep 13, 2012 at 15:45 UTC ( #993517=note: print w/ replies, xml ) Need Help??


in reply to hash to count words

#!/usr/bin/perl -w while (<>) { $COUNT{$_}++ for map lc, split /\W+/; } print "$_: $COUNT{$_}\n" for sort keys %COUNT;

Or if you're only interested in certain words...

#!/usr/bin/perl -w @W = qw( hello world ); while (<>) { $COUNT{$_}++ for grep { $_~~@W } map lc, split /\W+/; } print "$_: $COUNT{$_}\n" for sort keys %COUNT;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: hash to count 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://993517]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-04-17 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (440 votes), past polls