I'm confused on just what you're trying to do. I'm not sure you aren't as well.

# How to create a hash with keys only?

That's nonsensical. Keys are a way to find a value. You can create a hash of keys whose value is undef or 0 or an empty string or any temporary placeholder you want, but you can't have a "hash with keys only".

@insert = \%hash;

This creates a 1-array whose first element is a reference to an empty hash. I don't think that's what you want to do.

The rest of the code is at least superficially reasonable (if you put %ages before the lines where you try and reference it), but what's the purpose of %hash? What are you wanting to end up with?


In reply to Re: array/hash - reference and dereference by fullermd
in thread array/hash - reference and dereference by Anonymous Monk

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.