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.
|