Hello,

I'm trying to pass an anonymous hash to a sub the laziest way I possibly can. So I'm doing the usual:
get_ids({'id_one' => 1, 'id_two' => 2, 'id_three' => 3})

But what I'd really like to do is something like:
get_ids({'id_one','id_two','id_three'})

This doesn't seem to work. When I shift the hashref to a scalar in the sub the scalar only knows about the first key id_one when I dereference it using a map:
sub get_ids { $id_hashref = shift; map { print "key $_ exists in the request\n" } (keys %{$id_hashref +}); }

Is there a way to pass an anonymous hash to a sub without defining unnecessary values for all of the keys? I could pass an array and make it hash keys in the sub, but I'd really rather not. I have the funny feeling I'm missing something, but its 1am...:)

Thanks,
Alex


In reply to Pass anonymous hash - keys only? by blahblah

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.