Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to Re^3: Accessing Arguments inside Subroutines via @_
in thread Accessing Arguments inside Subroutines via @_

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! :)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)

PS: Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1120874]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-28 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found