in reply to Setting defaults in subroutines
You're being burnt by a combination of operator precedence and context.
my @index = @{$args{Index}} || ();
is interpreted as
my @index = (@{$args{Index}} || ());
Then the || operator forces scalar context on @{$args{Index}} which therefore gives the number of elements in the array (which is 2).
On the other hand,
is interpreted asmy @index = @{$args{Index}} or ();
(my @index = @{$args{Index}}) or ();
So the array is evaluated in list context and everything works as expected.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Setting defaults in subroutines
by rbi (Monk) on Aug 04, 2004 at 09:54 UTC | |
by PerlingTheUK (Hermit) on Aug 04, 2004 at 10:23 UTC |