1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @sel_keys = qw/red green/;
my %hash_source = ( red => '#ff0000', green => '#00ff00', blue => '#0000ff', );
my %hash_target = hashAssignByKeys(\%hash_source, @sel_keys);
print Dumper \%hash_target;
exit;
sub hashAssignByKeys {
my ($source, @keys) = @_;
map { $_, $source->{$_} } grep { exists $source->{$_} } @keys;
}
EDIT1: Ist fast das gleiche wie Taulmarills Lösung, nur in einem Rutsch und als Zuweisung.\n\n
<!--EDIT|Ronnie|1120565151-->