Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Autovivification of scalars in sub calls

by Perl Mouse (Chaplain)
on Dec 08, 2005 at 23:02 UTC ( #515409=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Autovivification of scalars in sub calls
in thread Autovivification of scalars in sub calls

sleep is not a sub. sleep is a buildin. In this, it makes all the difference. Subs have @_, and their arguments are aliased to it. Hence the lvalue of arguments to subs - but not to buildins (with a few exceptions).

Be that as it may, where can I learn more about this sub-args-as-lvalues thing? I can't find documentation for it.
Very early in man perlsub, as soon as it starts talking about @_. The third paragraph of the description:
Any arguments passed in show up in the array @_. There­ fore, if you called a function with two arguments, those would be stored in $_[0] and $_[1]. The array @_ is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable). If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array @_ removes that aliasing, and does not update any arguments.
Perl --((8:>*


Comment on Re^3: Autovivification of scalars in sub calls
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-04-20 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls