Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: testing parts of a string against a word database

by hbm (Hermit)
on Dec 01, 2011 at 00:57 UTC ( #940984=note: print w/ replies, xml ) Need Help??


in reply to testing parts of a string against a word database

I'd put the input into a hash; then scan nouns.txt (once) and for each word, see if it is in the hash.

use strict; use warnings; my %words = map { s/[.?!]$//; lc $_, $_ } split/\s+/,<STDIN>; open(NOUNS,'<',"nouns.txt") or die "Can't open noun database: $!\n"; while(<NOUNS>){ s/\s+//g; print "\n!MATCH! ~ $words{lc $_} is a noun\n" if exists $words{lc $_}; } close(NOUNS);


Comment on Re: testing parts of a string against a word database
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2015-07-07 05:46 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 (87 votes), past polls