Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Pass array, then clear

by Laurent_R (Canon)
on Jan 15, 2018 at 23:41 UTC ( [id://1207326]=note: print w/replies, xml ) Need Help??


in reply to Pass array, then clear

When you write:
my($data) = @_;
you're creating a new variable that happens to contain an array ref defined in the caller. Then you simply give another value (namely a reference to an empty array) to that variable. There should not be any reason why this would modify the original array ref.

Just as if you say:

my $c = 5; my $d = $c; $d = 6;
this will not change the value of $c.

In the commented out version, something else is happening: @$data is actually the array referred to by $data, so you are not modifying the local variable just created in the sub, but the value (the anonymous array referred to by the array ref) $data refers to.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found