Use this: if (map { (defined $hash->{$_})? 1 : () } qw(A B C)) map in scalar context returns the number of list elements generated.
Update: This is (probably) an inferior solution. I think it has to build the array in memory. I would use tilly's solution. But maybe map is implemented well and doesn't build the list when called in scalar context. Maybe someone with more knowledge than me could comment on that?
Update 2: Another thought ... when testing for the definedness of lots of keys an explicit loop with exit might be quicker because you don't have to test all elements. It's enough when the first key is not defined. grep and map always go through the whole list.
-- Hofmator
In reply to Re: Checking for defined-ness for a list
by Hofmator
in thread Checking for defined-ness for a list
by dragonchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |