Can "grep" take a condition, like only assign to "$zip_match" if it is true?
In the statement
my ($zip_match) = grep { $_ eq $zip } values %zips;
the condition grep takes is $_ eq $zip and it matches in list context, so it returns nothing (the empty list) if there is no match and assigns nothing to $zip_match which retains the uninitialized value (i.e., undef) with which it was created.
In reply to Re^3: Hash search and returning by value
by AnomalousMonk
in thread Hash search and returning by value
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |