Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: help with references

by moritz (Cardinal)
on May 04, 2013 at 19:18 UTC ( #1032073=note: print w/replies, xml ) Need Help??

in reply to help with references

Both times that the loop is run, \@a returns a reference to the same array, because it is the same array that's on the right of the \ character.

To avoid that, you can use $h{$i} = [@a] instead, which copies the array and returns a reference to the copy.

Replies are listed 'Best First'.
Re^2: help with references
by dw_perlmonks (Novice) on May 04, 2013 at 19:42 UTC
    Thanks for the reply, moritz! using your method i'm no longer getting a ref of @a, but now i get refs of the individual arrays instead. it still won't work because if i change the AoA in $h{"1"}, the AoA in $h{"2"} will also be modified.
    { '1' => [ [ 'a1', 1, 1, 1 ], [ 'a2', 2, 2, 2 ] ], '2' => [ $VAR1->{'1'}[0], $VAR1->{'1'}[1] ] }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032073]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-06-18 06:38 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.