Perl: the Markov chain saw | |
PerlMonks |
Re^4: Accessing Arguments inside Subroutines via @_by LanX (Saint) |
on Mar 22, 2015 at 12:06 UTC ( [id://1120874]=note: print w/replies, xml ) | Need Help?? |
Well you asked for the "why" not for the "how" ... :) I took a look into the Panther book and experimented with Devel::Peek and the implementation of aliases seems simpler than a magic data structure of type alias. Arrays (AVs) are composed from C-structures with pointers to C-structure(s) realizing scalars (SVs). So $_[0]=666 updates the underlying scalar ( what I called "assigning" ) while @_=(666) creates the pointer to a new scalar ( "setting" ). In the following dump the scalar value for $x is held within SV = IV(0x88f2498) at 0x88f249c The array's first slot will point to that same structure before and after updating with $_[0]=666 (#markers added) But creating new entries with @_=(666) will replace the pointer in this AV-slot to a new SV.
I hope the "how" is clearer now! :)
In Section
Seekers of Perl Wisdom
|
|