[Israel.pm] (no subject)

Yossi Itzkovich Yossi.Itzkovich at ecitele.com
Sun Oct 22 03:39:59 PDT 2006

Let's say I have a function  :
1 sub filterByField
2 { # find in the given array of hashes(==records) , thoese who have
hash key $fieldName that equals to $fieldValue
3 my ($fieldName,$fieldValue,$arrOfHashes)=@_;
4 my @retVal=grep ({defined $$_{$fieldName} and $$_{$fieldName} eq
$fieldValue} @$arrOfHashes);
5 }
currently the call is like:
6 my @handle=filterByField("User Name","Moshe");
It works, but it is limited, for example, for multiple conditions, or
I want to pass a code ref to that function, I will do the changed in
filterByField, and I will send the code block in line 4 as the code ref.
Question:  Should  $_ in the code block  really getd the iterator value
in grep for each iteration ?

More information about the Perl mailing list