|XP is just a number|
Re: Binary Search Tree Debug Questionby jdporter (Chancellor)
|on Aug 12, 2011 at 18:29 UTC||Need Help??|
Ok, you know that arguments are passed to subs in the special array @_. It just so happens that the actual elements of @_ are not simply copies of the actual argument values, but are aliases to them. If you were to do this:
$x remains unchanged, because $a is completely separate from $x. The assignment of ( $x ) to @a copies the value (5).
It's different with @_ when it's carrying the arguments of a sub call.
That's because $_ is not separate from $x; in fact, it is an alias to it. The "assignment" of ( $x ) to @_ does not copy values; it sets up aliases.
This behavior can be used to create "OUT" parameters; that is, parameters which can alter their arguments.
(Note that the actual argument would have to be writable for this to work. If we called foo( 5 ); with the above code, we'd get a "Modification of a read-only value attempted" error.)
I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.