Next | Tricks of the Wizards | 207 |
Here's a fine, fine trick.
Let's write a reduce call to ask if a list contains all positive numbers.
reduce { $a && $b > 0 } "yes", @list;
If you apply this to the list (0 .. 1000000), it goes all way to the end
Solution:
reduce { $a && $b > 0 || ($a=undef, last) } "yes", @list;
last?!
Yes! last is dynamically scoped!
Next | Copyright © 2003 M. J. Dominus |