Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 lurking in the Monastery: (6)
As of 2014-12-18 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls