in reply to Slice a hash to get a subset hash.
What I usually do is something like this (your final solution in the OP):
my %location = map { $_ => $london{$_} } qw(Long Lat Elevation);
However, if that isn't clean enough for you, you could use prototypes to create a bit of syntactic sugar:
sub extract(\%@) { my $h = shift; map { $_ => $h->{$_} } @_; } # usage my %location = extract %london, qw(Long Lat Elevation); my %stats = extract %london, 'Population', 'Area'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Slice a hash to get a subset hash.
by chrestomanci (Priest) on Feb 24, 2011 at 14:41 UTC |
In Section
Seekers of Perl Wisdom