Goto::Cached - a fast drop-in replacement for Perl's O(n) goto
sub factorial($) {
use Goto::Cached;
my $n = shift;
my $accumulator = 1;
iter: return $accumulator if ($n < 2);
$accumulator *= $n;
--$n;
goto iter;
}
Goto::Cached provides a fast, lexically-scoped drop-in replacement for Perl's
builtin goto
. Its use is the same as the builtin. goto &sub
and jumps out
of the current scope (including if
and unless
blocks) are not cached.
0.22
Copyright © 2005-2010 by chocolateboy.
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.