in reply to perlsub question..
You can't pass an array to a function.
If @a has 0 elements, func(@a) is the same as func().
If @a has 1 element, func(@a) is the same as func($a[0]).
If @a has 2 elements, func(@a) is the same as func($a[0], $a[1]).
If @a has 3 elements, func(@a) is the same as func($a[0], $a[1], $a[2]).
etc.
That's why the text speaks of an "array or hash element".
sub test1 { $a = $_[0]; } sub test2 { $_[0] = $a; } my @a; test1($a[0]); print(scalar(@a), "\n"); # 0 test2($a[0]); print(scalar(@a), "\n"); # 1
Update: Ah shoot! It had written $_[x] where I had meant to write $a[x]. Fixed. Thanks ysth and graff.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perlsub question..
by ysth (Canon) on Jun 24, 2007 at 19:17 UTC |