Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
if you don't really need references use aliasing !

DB<122> $a => 5 DB<123> sub alias_add { $_[0]+=2 } DB<124> alias_add $a => 7 DB<125> $a => 7

But to fully answer the original question:

DB<126> sub ref_add { ${ shift() }+=2 } DB<127> ref_add \$a => 9 DB<128> $a => 9 DB<129> sub ref_add2 { ${ +shift }+=2 } DB<130> ref_add \$a => 11 DB<131> $a => 11

update

or using parens

DB<102> $a=11 => 11 DB<103> sub ref_add3 { ${ (shift) }+=2 } DB<104> ref_add3 \$a; $a => 13

Cheers Rolf

( addicted to the Perl Programming Language)

1) from perlsub:

Any arguments passed in show up in the array @_. Therefore, 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).

In reply to Re: shift implicit dereference by LanX
in thread shift implicit dereference by Lennotoecom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2015-07-04 10:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (59 votes), past polls