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
In reply to Re^2: Filter array of hashes for specific keys
by ddominnik
in thread Filter array of hashes for specific keys
by ddominnik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |