Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: shift implicit dereference

by LanX (Bishop)
on Oct 06, 2013 at 13:39 UTC ( #1057148=note: print w/replies, xml ) Need Help??

in reply to shift implicit dereference

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


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).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057148]
Tanktalus is trying to figure out how to get a case-insensitive match between stra▀e and strasse to return true in perl :( fc doesn't seem to do it, either, unless I'm doing it wrong.
[LanX]: ▀,ss
[LanX]: nope
[LanX]: /.*(?:▀|ss).*/
[hippo]: How are you doing the match? Regex, index, eq or something else?
[choroba]: fc $s1 eq fc $s2 I guess
[Tanktalus]: hippo: I don't care, I just want to prove it can match correctly compared to, say, ILIKE / UPPER / LOWER in postgres :)
[LanX]: is there a unicode convention that ▀ is ss ?

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2018-03-21 15:37 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (268 votes). Check out past polls.