http://www.perlmonks.org?node_id=1038717


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)