Checking, I find that perl5.004 appears to throw away the last key whenever a hash is initialised from a list with an odd number of elements, whereas perl5.004_05 and later act as if there were an extra undef at the end of the list to make it even.

As a result, %a = (1, 2, 3) leaves %a containing one key ('1') in perl5.004 and two keys ('1', '3') in newer perls. I guess this came in as a bug fix sometime after the initial perl5.004 release, but I don't know exactly when, and I don't have any of the intermediate versions to check.

Even perl5.004 warns "Odd number of elements in hash list", so this is just another reason always to turn on warnings. :)

Hugo


In reply to Re: Construction/initialisation of empty hash by hv
in thread Construction/initialisation of empty hash by muntfish

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.