in reply to open annoyance
Perl applies scalar() to the first "argument" you pass proto() at compile-time. In this case, that's $args[0] and @args[0..$#args] -- in the former, there is no change, but in the latter, we end up getting the last element in the array! When you pass an array as the first element, it gets transmuted into its size. (But you probably knew most of this already.)sub proto ($@) { print "$_[0]; $_[1..$#_]\n"; } my @args = qw( a b c d e f ); proto($args[0], @args[1..$#args]); proto(@args[0..$#args]);
I've been in a similar situation. The simplest work-around I can think of is the one you've shown, where you separate the first element of the array from the others. Whether you do that destructively (as with shift) or with slices is a personal choice.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: open annoyance
by tlm (Prior) on Sep 29, 2005 at 13:40 UTC |