in reply to Re: Filter array of hashes for specific keys
in thread Filter array of hashes for specific keys
So far I've tried it myself this way:
sub filter { die 'Error: no fields to filter through' if (@_ < 2); my $response = shift; my @fields; foreach my $a (0..$#_) { $fields[$a]= shift; } if (ref $response eq 'ARRAY') { my @response = @$response; my @filtered_responsearr; my %filtered_response; foreach my $ref (@response) { my %response = %$ref; foreach my $field (@fields) { $filtered_response{$field}=$response{$field}; } push @filtered_responsearr, %filtered_response; } return \@filtered_responsearr; }
which returns an array of all the fields, like ['name','foo','id','bar','name','foo2','id','bar2']
But I don't need an array of all the fields, I need an array of hashes, because I have to work with the hashes afterwards
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Filter array of hashes for specific keys
by Corion (Patriarch) on Oct 21, 2016 at 09:50 UTC | |
by Eily (Monsignor) on Oct 21, 2016 at 10:00 UTC | |
by ddominnik (Novice) on Oct 21, 2016 at 10:40 UTC | |
|
Re^3: Filter array of hashes for specific keys
by rsFalse (Chaplain) on Oct 28, 2016 at 09:26 UTC |