Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by LanX (Chancellor)
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)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2017-02-21 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (313 votes). Check out past polls.