
BillKSmith
Veteran
Nov 8, 2011, 7:15 PM
Post #3 of 3
(535 views)
|
|
Re: [ssampath123] match part of a string in values of a hash
[In reply to]
|
Can't Post
|
|
It appears that you want "Found" printed only once even if a match occurs in several values. use strict; use warnings; use List::MoreUtils qw( any ); my %f1H = ( key1 => 'I love basketball', key2 => 'I love baseball', key3 => 'I love football very much', key4 => 'I watch Monday night footbal every week', ); my $val = qr /football/; if (any {$val} values %f1H) { print "Found\n" ; } You can replace 'any' with 'scalar grep' if you do not want to use the module. I prefer 'any' because it documents your intention. I see that you are using an integer (10) as a hash key. If all your keys are small integers, you probably should be using an array rather than a hash. Good Luck, Bill
(This post was edited by BillKSmith on Nov 8, 2011, 7:20 PM)
|