in reply to Dereference array-elements

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.

Replies are listed 'Best First'.
Re: Re: Dereference array-elements
by very empty (Scribe) on Jun 03, 2002 at 12:20 UTC
    Thanks a lot, this is very helpful and you are right,  %hash = %$hashref was what I have meant.
    It is also right, that looking up in a hash is always better and more perlish, but in my case the "primary key" is only primary at that moment.

    Regards...