in reply to Re^4: Tidy up conditions
in thread Tidy up conditions
The key 'foo' exists but the zero score makes perl evaluate the second operand, too. With perl version 5.10.0 and up, the defined-or operator can help, as it short-cuts only on undef:my %access = ('foo' => 0, 'bar' => 123); print $access{'foo'} || $access{'bar'}; # prints 123
Older perls don't have this operator, however.my %access = ('foo' => 0, 'bar' => 123); print $access{'foo'} // $access{'bar'}; # prints 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Tidy up conditions
by tel2 (Pilgrim) on Mar 20, 2015 at 05:23 UTC | |
|
Re^6: Tidy up conditions
by tel2 (Pilgrim) on Mar 21, 2015 at 01:35 UTC | |
by tye (Sage) on Mar 21, 2015 at 03:28 UTC | |
by tel2 (Pilgrim) on Mar 21, 2015 at 04:26 UTC | |
by martin (Friar) on Mar 22, 2015 at 02:33 UTC | |
by tel2 (Pilgrim) on Jul 07, 2015 at 23:31 UTC | |
by Anonymous Monk on Mar 21, 2015 at 02:53 UTC | |
by tel2 (Pilgrim) on Mar 21, 2015 at 04:25 UTC |