Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 romping around the Monastery: (13)
As of 2015-07-01 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (11 votes), past polls