I
Ivan Shmakov
Given @keys and a %hash, a list of values could be produced
easily, like:
my @vals
= @hash{@keys};
Likewise, for the list of references:
my @refs
= \@hash{@keys};
I wonder, is it necessary to use map to get a list of references
/considering the existing associations only/?
my @refs
= map { exists ($hash{$_}) ? \$hash{$_} : undef; } (@keys);
I don't care about the missing keys, BTW. Thus, I can use
something like the following instead, but it's even more
verbose.
my @refs = ();
foreach my $k (@keys) {
push (@refs, \$hash{$k})
if (exists ($hash{$k}));
}
easily, like:
my @vals
= @hash{@keys};
Likewise, for the list of references:
my @refs
= \@hash{@keys};
I wonder, is it necessary to use map to get a list of references
/considering the existing associations only/?
my @refs
= map { exists ($hash{$_}) ? \$hash{$_} : undef; } (@keys);
I don't care about the missing keys, BTW. Thus, I can use
something like the following instead, but it's even more
verbose.
my @refs = ();
foreach my $k (@keys) {
push (@refs, \$hash{$k})
if (exists ($hash{$k}));
}