Do you know where your variables are? | |
PerlMonks |
Re: shift implicit dereferenceby kcott (Archbishop) |
on Oct 06, 2013 at 17:39 UTC ( [id://1057173]=note: print w/replies, xml ) | Need Help?? |
G'day Lennotoecom, "... what that "+" stuff exactly does." A unary "+" is used for disambiguation. If you were to code ${shift}, that would be ambiguous: did you mean the variable $shift or a dereferencing operation on the value shifted off @_. Using a "+" indicates you meant the shift function and not a variable name. Consider this code:
Output:
You'll find this usage of "+" cropping up in many places. Here's some examples. Does the "(" following a function name start a list of arguments to the function?
Is "{...}" an anonymous block or a hashref constructor?
How can I tell a constant bareword and a hash key bareword apart?
Documentation for unary "+" usages appears to be rather scattered. For the three pairs of examples above, see "perlop: Symbolic Unary Operators", "perlref: Making References" and "constant: CAVEATS", respectively. There are other examples documented elsewhere. I couldn't locate any references to the ${+shift} example. -- Ken
In Section
Seekers of Perl Wisdom
|
|