in reply to how to find hash keys in a string ?
If you want to know where the matches occur, you can use map instead of grep.use strict; my %temphash = ("tom" => "good", "dick" => "bad", "hary" => "ugly"); my $string = 'This string contains tom and dick'; my @occurrences = grep {exists $temphash{$_}} split(/\s/, $string); print scalar @occurrences;
Is this faster than the regexp method? I'm not sure. The hash lookups are certainly quick enough...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: how to find hash keys in a string ?
by BrowserUk (Patriarch) on May 03, 2003 at 20:57 UTC | |
|
Re: Re: how to find hash keys in a string ?
by Limbic~Region (Chancellor) on May 04, 2003 at 03:54 UTC | |
by Dr. Mu (Hermit) on May 04, 2003 at 07:59 UTC |