Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to add to hash of a hash of an array. Confused.com!

by LanX (Canon)
on Jun 13, 2013 at 10:19 UTC ( #1038717=note: print w/ replies, xml ) Need Help??


in reply to How to add to hash of a hash of an array. Confused.com!

You are posting broken code, the '(' after push is never closed. Did this ever compile for you?

Perl does autovivification, so no need to test for existence.

Just push (and use valid syntax)!

DB<105> push @{ $hash{A1}{B2}{C1} }, "arrayitem4"; => 1 DB<106> \%hash => { A1 => { B2 => { C1 => ["arrayitem4"] } } } DB<107> push @{ $hash{A1}{B2}{C1} }, "arrayitem1"; => 2 DB<108> \%hash => { A1 => { B2 => { C1 => ["arrayitem4", "arrayitem1"] } } } DB<109> push @{ $hash{A1}{B2}{C2} }, "arrayitem2"; => 1 DB<110> \%hash => { A1 => { B2 => { C1 => ["arrayitem4", "arrayitem1"], C2 => ["arrayite +m2"] }, }, }

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re: How to add to hash of a hash of an array. Confused.com!
Download Code

Log In?
Username:
Password:

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

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

    When choosing user names for websites, I prefer to use:








    Results (256 votes), past polls