Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

If you just want words...

by tedv (Pilgrim)
on Jan 17, 2001 at 01:37 UTC ( #52366=note: print w/replies, xml ) Need Help??


in reply to Re: Re: How can I use regex to copy each word of a string into a hash?
in thread How can I use regex to copy each word of a string into a hash?

If you just want words, why bother with punctuation at all? Just do a massive s/\W+/ /g on the string beforehand and you'll get a big list of words, separated by spaces. I suppose those damn apostrophies will cause you pain, and you want "it's" to differ from "its". It's unclear whether or not capitalization matters-- is "BASIC" a different word from "basic"? What about "Smith" versus "smith"?

Anyway, I'd probably write something like this:
local $/ = undef; $_ = <MY_FILE>; my %hash = (); $hash{$_}++ foreach split /[^\w']+/; # Change $_ to lc if case matters


-Ted

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://52366]
help
Chatterbox?
[marinersk]: LanX, the problem is that the lack of interface visual stability is disconcerting to me. The Nodelet appearing and disappearing is distracting, and despite over a decade, still troubles me. It jangles me.
[LanX]: I see
[marinersk]: I appear to be unusually dependent on spacial stability. I have had trouble from someone moving an object a mere four inches to the left.
[Eily]: I think the solution is to write posts so brilliant that you gain XP on each refresh, no matter how often :P
[marinersk]: Eily++ and LOL
[marinersk]: I get a lighter version of this disconcertion (new word?) when the n points remaining until rank disappears.
[choroba]: :-D
[marinersk]: I've often marvelled over the past few decades at just how little it takes to mess me up with this spacial dependence thing. I wonder if I'm mildly autistic or something.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-05-29 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?