in reply to How to filter few key value pairs from hash reference
for my $href ( @data ) { my $copy_ref = { %$href }; delete $copy_ref->{sex}; push @{ $data2->{$href->{sex}} }, $copy_ref; }
Or, you can construct the target hash on the fly:
for my $href (@data) { push @{ $data3->{ $href->{sex} } }, { map 'sex' eq $_ ? () : ( $_ => $href->{$_} ), keys %$href } +; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to filter few key value pairs from hash reference
by jaypal (Beadle) on Sep 15, 2014 at 17:23 UTC |