Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Pass array, then clear

by Crackers2 (Parson)
on Jan 16, 2018 at 18:27 UTC ( #1207364=note: print w/replies, xml ) Need Help??


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

I did not suspect that the subroutine made a copy of the memory address

It doesn't. You do, with the my($data) = @_; snippet. If you directly manipulate the argument, it works as you expect:

sub clear_it { $_[0] = []; }

Because you're then working on the original reference, not on the copy you made.

Replies are listed 'Best First'.
Re^4: Pass array, then clear
by Anonymous Monk on Jan 16, 2018 at 18:37 UTC
    Thank you, I did not realize that!
Re^4: Pass array, then clear
by Anonymous Monk on Jan 16, 2018 at 20:36 UTC
    This reply really brings it home for me. Light coming on strongly (or is it just the flames of the reference burnage?). I now see the error of my ways.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (None)
    As of 2021-10-16 03:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My first memorable Perl project was:







      Results (69 votes). Check out past polls.

      Notices?