in reply to Unintialised value?
my % pages = ( 'index' => 1, 'me' => 1, 'stuff' => 1, 'links' => 1 ); my $page = shift; exit 0 unless exists $pages{$page} and $pages{$page} == 1;
This will not generate the uninitialized value warning, because the right hand side equality test only gets evaluated if the left side of the logical short-circuit 'and' evaluates to truth first (if the hash key exists).
If you happen to be in a situation where the key might exist but without any initialized value, you could chain a defined in there...
exit 0 unless exists $pages{$page} and defined $pages{$page} and $pages{$page} == 1;
Not terribly elegant, but it does take into consideration all the possibilities.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Unintialised value?
by Not_a_Number (Prior) on Jan 25, 2004 at 19:37 UTC | |
by davido (Cardinal) on Jan 26, 2004 at 03:03 UTC |