You cannot have duplicate keys with a hash. Besides the hard-coded 'data' hash key does not seem to make much sense, and I am not convinced that the data structure you are using is the best one, but it may be because you showed only a small part of your code. If you really need an array of hashes, then you should probably change it to an array of hashes of arrays, or you could possibly use an array of arrays. An example of one possibility under the Perl debugger:
DB<4> @values = qw / 60 811/; DB<5> push @{$AoA[$values[0]]}, $values[1]; DB<6> @values = qw / 60 812/; DB<7> push @{$AoA[$values[0]]}, $values[1]; DB<8> x \@AoA 0 ARRAY(0x80430518) 0 empty slot 1 empty slot 2 empty slot 3 empty slot (...) 58 empty slot 59 empty slot 60 ARRAY(0x803f50f0) 0 811 1 812
This shows, however, that using an array as the first level of the data structure is probably not the best idea: these 60 empty slots are a waste of memory. A HoA might be better:
DB<1> ($key,$val) = qw / 60 811/; DB<2> push @{$HoA{$key}}, $val; DB<3> ($key,$val) = qw / 60 812/; DB<4> push @{$HoA{$key}}, $val; DB<5> x \%HoA 0 HASH(0x80359cb0) 60 => ARRAY(0x8035ffa8) 0 811 1 812 DB<6> print "@{$HoA{60}}" 811 812

In reply to Re: ID exists in Hash -I need to copy the value even if it exists more than one by Laurent_R
in thread ID exists in Hash -I need to copy the value even if it exists more than one by MSOL

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.