in reply to Bitten by the || bug
For hack value, here is an expressive version:
sub also_correct { @{ ( map { @$_ ? $_ : [ list1() ] } [ list0() ] )[0] } }
(For some reason @{} executes its expression in void scalar context, which necessitates the ()[0] gymnastics to force the correct context on map, which would otherwise return 1. That cost me some time to track down, because I was testing on the shell in one-liners with no strict. In retrospect that was stupid, considering I was testing code with references.)
This is the list-context equivalent of list0() || list1() and has the same short-circuiting behaviour as ||.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bitten by the || bug (@{})
by tye (Sage) on Feb 20, 2006 at 16:53 UTC | |
by Aristotle (Chancellor) on Feb 21, 2006 at 01:37 UTC | |
by Aristotle (Chancellor) on Feb 20, 2006 at 18:34 UTC | |
by tye (Sage) on Feb 20, 2006 at 18:52 UTC |