in reply to Re^3: perlsub question..
in thread perlsub question..
Elements of @_ are aliased to EXISTING/DEFINED elements of the passed parameter.Not necessarily.
perl -MData::Dump::Streamer -le '@ary = (); x($ary[5],"foo"); sub x { +$_[0] = $_[1] }; Dump(\@ary)' $ARRAY1 = [ ( undef ) x 5, 'foo' ]; perl -MData::Dump::Streamer -le '@ary = (); x($ary[5],"foo"); sub x { +$_[0] }; Dump(\@ary)' $ARRAY1 = [];
As you can see, the element at index 5 is not created merely by passing its alias to the sub. It doesn't exist and isn't defined, and may remain so after the sub has been called.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: perlsub question..
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 | |
by ysth (Canon) on Jun 24, 2007 at 21:49 UTC | |
by shmem (Chancellor) on Jun 24, 2007 at 21:59 UTC | |
by ysth (Canon) on Jun 24, 2007 at 22:53 UTC | |
|