Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Pass array, then clear

by Anonymous Monk
on Jan 15, 2018 at 22:09 UTC ( [id://1207318]=note: print w/replies, xml ) Need Help??


in reply to Re: Pass array, then clear
in thread Pass array, then clear

Thank you for the explanation. Do you think this is intuitive behavior when dealing with references? I'm kind of bummed about it. I'm concerned that this behavior deserves an explanation somewhere. I'm sure it's in the documentation somewhere, but I did not see anything about this in the Perl references documentation.

Maybe everyone thinks the current behavior is perfect, in that case I need to adjust my thinking.

Replies are listed 'Best First'.
Re^3: Pass array, then clear
by AnomalousMonk (Archbishop) on Jan 15, 2018 at 23:34 UTC
    Do you think this is intuitive behavior ...? I'm concerned that this behavior deserves an explanation somewhere.

    No, it's not intuitive; however, this is pretty much the way references work in any computer language. Maybe see reference, perlref, perlreftut. Perhaps also take a look at the Monastery Tutorials articles in References, and maybe also at Coping with Scoping and other articles in Variables and Scoping.

    (And yes, you need to adjust your thinking :) (Update: And yes, references and aliasing have bitten me, too — many times, many, many times...)


    Give a man a fish:  <%-{-{-{-<

Re^3: Pass array, then clear
by huck (Prior) on Jan 15, 2018 at 22:22 UTC

    I will admit i have gotten bit by it before, but as soon as i realize i know what to fix. It is the same when

    for my $var (@array) { $var++; }
    ends up modifying the array even tho i said my $var.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found