Search code examples
perldictionaryweak-typing

Is using nested map in perl a good practice?


my @c= map {
        my $v=$_;
        map {$_ * $v } @m
} @a;

Is using map like this, a good practice? Why not? If not, what are other ways?


Solution

  • I cannot answer whether or not it is good practice. In general there are a lot of situations in which I use nested maps a lot. It's short, it's concise and to the point.

    However, such nested maps are always in danger of growing just slightly too big and unwieldy in which case they become harder to read than they have to (which list does $_ refer to in which case!?). So use them, yes, but use it with caution -- just like all other similar things that make Perl so terse and expressive.