Home: Perl Programming Help: Intermediate:
Searching a Hash


Nov 23, 2000, 4:25 PM

Views: 243
Searching a Hash

I have a Quick (Maybe not so Simple Question).

I am wondering how to search for a word/sentance in a hash, so that if it finds the word/sentance it will return the hash KEY's to the user.

I have been having problems with this and hope someone can give me an Example to learn from.

Thanks for the help, Kao


Nov 23, 2000, 7:45 PM

Views: 243
Re: Searching a Hash

This depends entirely on how your hash is set up. Are the values in the hash long paragraphs? If so, you might want to do something like:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

my @results;
while (my ($k,$v) = each %hash) {
push @results, $k if index($v,$sentence) > -1;

Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher