So heres my simplification
Usually (yes there are exceptions) map {} grep{} or grep{} map{} can be simplified into#Initial code... @array = (['EMBL','a','b'],['c','d'],['EMBL','e','f']); $list = join "\n", map {${$_}[1],${$_}[2]}grep { ${$_}[0] eq "EMBL" } +@array; print $list; #first step convert the ${$_}[$index] to $_->[$index] $list = join "\n", map { $_->[1],$_->[2] } grep { $_->[0] eq "EMBL" } +@array; #second step convert to list slice $list = join "\n", map { @{$_}[1,2] } grep { $_->[0] eq "EMBL" } @arra +y; #next step simplify map{}grep{} into just map{} $list = join "\n", map { $_->[0] eq "EMBL" ? @{$_}[1,2] : () } @array +; print "\nSimplified:\n$list";
With greater efficiency and easier understanding (er on the latter IMO :-).map { (grep_condition) ? map_function : () }
Yves / DeMerphq
--
When to use Prototypes?
In reply to Re: Re: about grep....
by demerphq
in thread Mapping elements returned from a grep statement
by agustina_s
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |