in reply to Dereference array-elements

This assumes that there is at least one:

my %hash = %{(grep {exists $_->{'foo'}} @hashes)[0]};

Your code is incorrect in both lines. In the first, $hashref will be set to the number of matches, and you need %hash=%$hashref in the second. Recommend tye's References quick reference to help with errors like that

Perl hashes don't really have 'primary' keys in the way that databases do.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Dereference array-elements
by Abigail-II (Bishop) on Jun 03, 2002 at 13:48 UTC
    my %hash = %{(grep {exists $_ -> {foo}} @hashes) [0] || {}};

    And then it even works if there's no match.

    Abigail