I don't know what you did in the first version, but I get a warning message there too. Could it be that you had warnings off in that version?

To find such bugs it is often helpful to add a line like print ":$_[0]:$_[1]:$_[2]:\n"; before the problem line

The reason is that your array (of hashes) is empty, $array_of_hashes[0] does not exist. If you add a line  push @array_of_hashes,{}; before the call of Add_key_and_value, the warning vanishes

UPDATE: My observation that I got a warning message for the first version was wrong, the warning came from the print statement I added. Doh


In reply to Re: Passing a reference to an element in an array of hashes by jethro
in thread Passing a reference to an element in an array of hashes by textual

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.