dragonchild has asked for the wisdom of the Perl Monks concerning the following question:
I would much rather do something more Perl-ish. I came up with the following:if (defined $hash->{A} && defined $hash->{B} && defined $hash->{C}) { }
This works, but I was curious if there was a better way. (At least, one that doesn't involve grep /1/, which just looks ugly to me...)my $hash = { A => 1, B => 1, C => 1, }; if (grep /1/, map { !defined $hash->{$_} } qw(A B C)) { print "At least one undefined!\n"; } else { print "All there!\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Checking for defined-ness for a list
by japhy (Canon) on Jul 25, 2001 at 19:39 UTC | |
|
Re (tilly) 1: Checking for defined-ness for a list
by tilly (Archbishop) on Jul 25, 2001 at 19:36 UTC | |
by merlyn (Sage) on Jul 25, 2001 at 20:15 UTC | |
|
Re: Checking for defined-ness for a list
by Hofmator (Curate) on Jul 25, 2001 at 19:39 UTC | |
by dragonchild (Archbishop) on Jul 25, 2001 at 21:26 UTC | |
by Hofmator (Curate) on Jul 25, 2001 at 21:37 UTC | |
|
Re: Checking for defined-ness for a list
by runrig (Abbot) on Jul 25, 2001 at 21:51 UTC | |
|
Re: Checking for defined-ness for a list
by elbie (Curate) on Jul 25, 2001 at 22:58 UTC |