Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Hash of arrays generation

by GrandFather (Sage)
on Sep 05, 2012 at 01:47 UTC ( #991719=note: print w/replies, xml ) Need Help??

in reply to Hash of arrays generation

I'd use:

$HoA{$key} = \@fields;

unless I really wanted to copy the elements in @fields. Most often I'd do that sort of thing in a loop where @fields is local to the loop and the assignment is performed at the end of the loop block.

The trap with either of variants you show is that only a shallow copy is made. If @fields contains nested elements then the references are copied, not the nested data. Using \@fields makes it just a little clearer (at least to me) in that case that danger lurks under the surface because it is clearer that there isn't much copying going on.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Hash of arrays generation
by nemesisgus (Acolyte) on Sep 05, 2012 at 14:56 UTC
    Good point, thanks for the advice GrandFather.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991719]
[stevieb]: hmmm seems the C# library doesn't work right on win10. With berrybrew, only part of the perl portable zip is extracted. no errors nothing. Guess I have to look at switching out zip libraries. sigh

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-03-28 16:27 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (335 votes). Check out past polls.