in reply to Figuring out some data structure

A small point further to the excellent replies of Corion and gmargo:

While the OP defines the state of the  %labels hash, it does not say if  $tablename is initialized or not; the signs and symptoms will differ in the two cases (assuming warnings and strictures are used – as they always should be!).

If  $tablename is undefined, it will be 'coerced' to the empty string, which is a valid hash key.

>perl -wMstrict -le "my %labels; my $tablename; $_ = 'foo'; push @{ $labels{$tablename} }, $_; use Data::Dumper; print Dumper \%labels; " Use of uninitialized value $tablename in hash element at .... $VAR1 = { '' => [ 'foo' ] }; >perl -wMstrict -le "my %labels; my $tablename = 'bar'; $_ = 'foo'; push @{ $labels{$tablename} }, $_; use Data::Dumper; print Dumper \%labels; " $VAR1 = { 'bar' => [ 'foo' ] };