You can't pass an array to a subroutine! You can pass the values of an array (which is what you did) or a reference to an array. Consider this:
Now what's Perl supposed to do with this? Keep in mind that the foo() did not get two parameters, it got FOUR. The three elements of @a and the 666. The first three modifiable, the last readonly. No array was passed.sub foo { print "@_\n"; push @_, 99; } @a = (1,2,4); foo(@a, 666)
The docs talk about things like foo( $a[99]) and foo( $h{new_key}), where in an old version the @a would be expanded and the 'new_key' key added into the %h upon calling the subroutine, while in the new versions this is only done if necessary.
This is consistent with things like if (defined($a[99]){... versus $a[99] = 0;.
In reply to Re^2: perlsub question..
by Jenda
in thread perlsub question..
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |