my %new2 =
hmap { $_[1]{nick} =~ /rbush|fred/
? $_[0] => { hmap { $_[0], $_[1] } %{$_[1]} }
: ()
} %$h;
####
bash-3.2$ perl hmap_good2.pl
syntax error at hmap_good2.pl line 39, near "] =>"
syntax error at hmap_good2.pl line 40, near ":"
Execution of hmap_good2.pl aborted due to compilation errors.
####
use Data::Dumper;
my $h =
{
1 =>
{
nick => 'rbush',
phone => '5551212',
bday => '3/12/1965',
},
3 =>
{
nick => 'ernest',
phone => '5553300',
bday => '3/12/1971',
},
5 =>
{
nick => 'fred',
phone => '1112300',
bday => '5/01/1972',
},
};
sub hmap (&$)
{
my $code = shift;
my @i = %{ shift() };
my @rv;
push @rv, $code->(shift @i,shift @i) while @i;
return { @rv };
}
my %new2 =
hmap { $_[1]{nick} =~ /rbush|fred/
? $_[0] => { hmap { $_[0], $_[1] } %{$_[1]} }
: ()
} %$h;
print Dumper ($new2), "\n";
####
my $new2 =
hmap { $_[1]{nick} =~ /rbush|fred/
? ($_[0] => hmap { $_[0], $_[1] } $_[1])
: ()
} $h;