pike has asked for the wisdom of the Perl Monks concerning the following question:
$val = $x || $default
Now I tried this for lists, but it doesn't work - or, to be precise, it works only if the first list is empty, because otherwise the first list is interpreted in scalar context:
@a = (); @b = qw (one two three); @c = qw (four five); @d = @a || @c; #gives ('four', 'five') - OK @d = @b || @c; #gives ('3') - yikes!
Can I inhibit the interpretation of the first list as scalar? Or is the only way to get the desired behaviour:
@list = @a; @list = @default unless @list;
Thanks for your suggestions,
pike
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: default values for lists
by fglock (Vicar) on Sep 17, 2002 at 15:03 UTC | |
by pike (Monk) on Sep 17, 2002 at 17:15 UTC | |
by fglock (Vicar) on Sep 17, 2002 at 17:33 UTC | |
by Aristotle (Chancellor) on Sep 17, 2002 at 21:14 UTC | |
|
Re: default values for lists
by Elgon (Curate) on Sep 17, 2002 at 15:09 UTC | |
|
Re: default values for lists
by RMGir (Prior) on Sep 17, 2002 at 15:12 UTC | |
|
Re: default values for lists
by blokhead (Monsignor) on Sep 17, 2002 at 17:42 UTC |