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.

In reply to Re: error creating hash of array by graff
in thread error creating hash of array by HarshaHegde

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.