in reply to map with empty item

The problem is that the expression $_->{key} => $_->{value} if($_->{key} =~/^a\d+/) will still return something if $_->{key} =~/^a\d+/ doesn't match.    You should try it like this:

my %ret = map $_->{key} =~ /^a\d/ ? ( $_->{ key } => $_->{ value } ) : + (), @$data1;

Replies are listed 'Best First'.
Re^2: map with empty item
by remiah (Hermit) on Mar 15, 2012 at 05:55 UTC
    Thanks for reply.

    As Eliya and you points out, I have to care for not match case with empty list. Thanks.