in reply to Conditional array initialisation?
Using defined doesn't make sense here (see also hdb's reply), and the other expression has to be analogous to
DB<125> @a=() DB<126> @a = (@a || ( 1..3 )); => (1, 2, 3) DB<127> @a = (@a || ( 4..6 )); => 3
But the second case fails cause the LHS of an or operator is evaluated in scalar context.
We had a longer discussion about this some weeks ago, which I didn't really follow (maybe somenone can link to it)
FWIW this works:
DB<138> @a=() DB<139> @a = (4..6) if !@a => (4, 5, 6) DB<140> @a=() DB<141> @a = @a ? @a : ( 1..6 ) ; => (1, 2, 3, 4, 5, 6) DB<142> @a = @a ? @a : ( 42 ) ; => (1, 2, 3, 4, 5, 6) DB<143> @a = (4..6) if !@a => "" DB<144> \@a => [1, 2, 3, 4, 5, 6]
Cheers Rolf
( addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Conditional array initialisation?
by BrowserUk (Patriarch) on Jul 12, 2013 at 19:58 UTC | |
by LanX (Saint) on Jul 12, 2013 at 20:19 UTC | |
by BrowserUk (Patriarch) on Jul 12, 2013 at 21:24 UTC | |
by tye (Sage) on Jul 13, 2013 at 02:16 UTC | |
by Athanasius (Archbishop) on Jul 13, 2013 at 03:49 UTC | |
| |
by BrowserUk (Patriarch) on Jul 13, 2013 at 03:28 UTC | |
|