Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Top five words by occurrence

by Anonymous Monk
on Jul 19, 2005 at 11:04 UTC ( [id://476035]=note: print w/replies, xml ) Need Help??


in reply to Top five words by occurrence

Is this because I am using split? Is there a better way to go about this.
Yes. You're splitting on whitespace, and there's no whitespace between uncomfortable and its following comma. Instead of splitting on whitespace, you might want to extract sequences of word characters - instead of
my @words = split;
you'd write:
my @words = /\w{5,}/g;
with the added benefit of not having to test of word length anymore, you're extracting words consisting of at least 5 characters.
I am sure I will start missing words that have apostrophes too.
Indeed. Extracting word characters will miss words containing apostrophes. Or hyphens. Extracting words from a random text, where the words can contain punctuation is not a trivial thing to do.

A'mous-Monk

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found