in reply to error creating hash of array

You want to get rid of the "if ... else ..." logic in your code snippet, and just always do the "push" for every iteration. As it is, each new hash key you create in %HoA gets a string value, and when you try to "push" a new element onto a string, you get the error.

When you just do this:

my %HoA; foreach my $key (keys %$ref_to_HoH){ my $type = $$ref_to_HoH{$key}{TABLE_TYPE}; push @{$HoA{$type}},$key; }
Perl autovivifies a hash element with $type as the key whenever there is a new value in $type, and creates a ref to a new array as its value; it then pushes the string $key onto the array.

Replies are listed 'Best First'.
Re^2: error creating hash of array
by HarshaHegde (Sexton) on Nov 04, 2007 at 18:23 UTC
    Works great! Thanks graff!