Next | Tricks of the Wizards | 205 |
map and grep are great.
Wouldn't it be nice to make some new, similar operators?
Example:
$n = reduce { $a + $b } 1, 4, 2, 8, 5, 7
(Yields the sum, 27)
$n = reduce { $a * $b } 1, 4, 2, 8, 5, 7
(Yields the product, 2240)
$n = reduce { $a > $b ? $a : $b } 1, 4, 2, 8, 5, 7
(Yields the max, 8)
$n = reduce { [@$a, $b] } [], (1, 4, 2, 8, 5, 7)
(Yields a list, [1,4,2,8,5,7])
Next | Copyright © 2003 M. J. Dominus |