in reply to Re^2: Filter array of hashes for specific keys
in thread Filter array of hashes for specific keys
You want to push a hash reference and not a hash:
push @filtered_responsearr, \%filtered_response;
Your code can be greatly simplified in some other places:
my $response = shift; my @fields; foreach my $a (0..$#_) { $fields[$a]= shift; }
can be rewritten as a single assignment:
my( $response, @fields ) = @_;
Likewise, copying the elements of %response into the filtered response can be done using a hash slice instead of the loop:
@filtered_response{ @fields } = @response{ @fields }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Filter array of hashes for specific keys
by Eily (Monsignor) on Oct 21, 2016 at 10:00 UTC | |
|
Re^4: Filter array of hashes for specific keys
by ddominnik (Novice) on Oct 21, 2016 at 10:40 UTC |