in reply to Re: Array of Hashes
in thread Array of Hashes

Thanks friedo. But I am getting the following error when trying to run your code.
"Modification of a read-only value attempted at" the following line.

my @elements = grep { exists $_->{$captureId} } @outputFiles;

Replies are listed 'Best First'.
Re^3: Array of Hashes
by friedo (Prior) on Sep 20, 2005 at 17:48 UTC
    I don't get that error. Are you certain that what you have is an array of hashes? Here is a one-liner which shows that it works:

    perl -Mstrict -Mwarnings -MData::Dumper -e 'my @array = ( { foo => 1 }, { }, { }, { foo => 2 } ); my @elements = grep { exists $_->{foo} } @array; print Dumper \@elements' $VAR1 = [ { 'foo' => 1 }, { 'foo' => 2 } ];