3 ms·
For loops in perl have two styles. The first is the c-style loop, the other is a map. One often uses the latter style a lot more often.
by Sanddancer 12y ago
For loops in perl have two styles. The first is the c-style loop, the other is a map. One often uses the latter style a lot more often.
- pyre 12y agoThat, and Perl has an actual `map` function too: map { $_ + 1 } (@list);
- huehue 12y agoSometimes Perl can be a beauty: sub sum_of_squared_pairs { reduce { $a + $b } map { $_ * $_ } grep { $_ % 2 == 0 } @_ } sub schwartzian_transform { map { $_->[0] } sort { $a->[1] <=> $b->[1] } # use numeric comparison map { [$_, length $_] } # calculate the length of the string @_ }
- eru 12y agoYes, but _ has dynamic scope (I believe). That's very dangerous in general.