I wonder if I can get the hash instead of the hashref with a single line.

This is Perl. You can :)

First, let me state that %hash = $$hashref isn't going to do what you want. You probably meant %hash = %$hashref there. This can also be written as %hash = %{ $hashref } which brings me to:

%hash = %{ grep { has_the_right_primary_key($_) } @hashes };
But that too does not work. This is because grep doesn't return what you want in scalar context. Your own example has the same problem. Maybe something like this helps (I also changed the code block to a normal expression):
%hash = %{ ( grep hash_the_right_primary_key($_), @hashes )[0] };
BUT... I think you should have been using %hashes, not @hashes. Do not grep if you can look it up in a hash. This is something you will have to figure out yourself.

Good luck.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.


In reply to Re: Dereference array-elements by Juerd
in thread Dereference array-elements by very empty

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.