in reply to Consise way to filter out keys with undef values from a hash slice?
So you want to filter-in hash elements that have a defined value:
my %args = (profile => 'foo'); my %ta = map {defined($args{$_} ? ($_ => $args{$_}) : ()} qw(profile u +ser password);
If a map iteration returns an empty list, nothing gets added to the recipient's list. I don't usually like making map behave like grep, but in this case it seems a reasonable fit.
grep behavior can be provided by map by adding a Boolean test and a conditional return value.
my @array = grep {COND} LIST; my @array = map {COND ? $_ : ()} LIST
Dave
In Section
Seekers of Perl Wisdom