Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: a question about making a word frequency matrix

by l3v3l (Monk)
on Dec 08, 2005 at 00:16 UTC ( [id://515084]=note: print w/replies, xml ) Need Help??


in reply to a question about making a word frequency matrix

I know this is not a working solution to your query but is a one-liner that I have used often to get this type of information quickly for any block of text I am dealing with:
perl -nle '$c{$_}++ for split/\s/;}print map {"$_:$c{$_}\n"} sort{$c{$ +b}<=>$c{$a}}keys %c;{' file_of_WHATEVER_to_count.txt
example, to count the number of instances of each word in a file you could use split/\W/ in the place of split/WHATEVER/ or just split if you wanted to keep punctuation,etc. intact. output is ordered by most frequent occurrences (at the top of the "item:count\n" listing)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found