Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Hash arrays

by BillKSmith (Chaplain)
on Dec 26, 2012 at 14:50 UTC ( #1010390=note: print w/ replies, xml ) Need Help??


in reply to Re: Hash arrays
in thread Hash arrays

    push @{ $family_hash{$key} }, @values;

I prefer

$family_hash{$key} = [@values];
Bill


Comment on Re^2: Hash arrays
Select or Download Code
Re^3: Hash arrays
by NetWallah (Abbot) on Dec 26, 2012 at 16:30 UTC
    Yes - that looks cleaner, but it is not the equivalent.

    Your code overwrites the contents of $family_hash{$key} while the OP's appends.
    So, if the $key appears more than once in the input data sequence, all but the last will be clobbered by your code.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-08-01 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls