OK, this is a "what's wrong with my code" question, which is probably an inappropriate use of this site

Not at all. It looks like you've made a effort to cut the problem down to the minimum amount of code. That's exactly the kind of problem that we're happy to help with.

You've been given the correct answer by a few people, but I thought you might be interested in a couple of other clues that you could have got for yourself.

If you had "use warnings" in your code, then you would have seen this error message:

Reference found where even-sized list expected

Which is true (as you now know from seeing what the problem is) but perhaps not as clear as it could have been. To get more help when tracking down a weird error like that, you can add "use diagnostics" to your code and Perl will then give you a complete description of the problem. In this case, it would have said the following:

You gave a single reference where Perl was expecting a list with an even number of elements (for assignment to a hash). This usually means that you used the anon hash constructor when you meant to use parens. In any case, a hash requires key/value pairs.

%hash = { one => 1, two => 2, }; # WRONG %hash = [ qw/ an anon array / ]; # WRONG %hash = ( one => 1, two => 2, ); # right %hash = qw( one 1 two 2 ); # also fine

So, in this case, I think that Perl would have given you exactly the help you were looking for to solve your problem.


In reply to Re: What causes HASH to print? by davorg
in thread What causes HASH to print? by kmullin5016

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.