in reply to Re: perlsub question..
in thread perlsub question..
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;.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: perlsub question..
by NetWallah (Canon) on Jun 23, 2007 at 20:22 UTC | |
by shmem (Chancellor) on Jun 23, 2007 at 20:46 UTC | |
by NetWallah (Canon) on Jun 24, 2007 at 14:38 UTC | |
by ysth (Canon) on Jun 24, 2007 at 19:09 UTC | |
by NetWallah (Canon) on Jun 24, 2007 at 20:53 UTC | |
|