Autovivification - Hashes

Hashes

The debugger session below illustrates autovivification of a hash:

DB<1> $h{A}{B}{C}{D}=1 DB<2> x \%h 0 HASH(0x83c71ac) 'A' => HASH(0x837d50c) 'B' => HASH(0x83c71e8) 'C' => HASH(0x83c7218) 'D' => 1 DB<3>

Hashes several layers deep were created automatically without any declarations. Autovivification can prevent excessive typing. If Perl did not support autovivification, the structure above would have to be created as follows:

DB<1> %h = (A => {B => {C => {D => 1}}}) DB<2> x \%h 0 HASH(0x83caba4) 'A' => HASH(0x83cfc28) 'B' => HASH(0x83cab74) 'C' => HASH(0x83b6110) 'D' => 1 DB<3>

Read more about this topic:  Autovivification