in reply to Figuring out some data structure

What's happening is "autovivification" of an array reference.

A quote from the book:
Programming Perl, 3rd Ed., p.251
Chapter 8: References
"Implicit Creation of References"

References of an appropriate type simply spring into existence if you dereference them in an lvalue context that assumes they exist.

So your statement:

push @{$labels{$tablename}}, $_;
is the same as:
$labels{$tablename} = [] if !exists $labels{$tablename}; push @{$labels{$tablename}}, $_;
See also autovivification in the glossary, and perlref.

Replies are listed 'Best First'.
Re^2: Figuring out some data structure
by ikegami (Patriarch) on Nov 01, 2009 at 18:29 UTC

    Small nit: It's more like

    $labels{$tablename} = [] if !defined $labels{$tablename}; push @{$labels{$tablename}}, $_;

      I stand corrected.
      If the $labels{$tablename} already exists but has an undefined value, then that "undef" is replaced with a reference to new anonymous array. I wish this was documented better.