FunctionalPerl
view release on metacpan or search on metacpan
t/perl/weaken-coderef-alternative view on Meta::CPAN
#!/usr/bin/env perl
# Copyright (c) 2015 Christian Jaeger, copying@christianjaeger.ch
# This is free software. See the file COPYING.md that came bundled
# with this file.
use strict;
use warnings;
use warnings FATAL => 'uninitialized';
use Scalar::Util "weaken";
sub foo {
my $f = sub {
my ($f, $n) = @_;
sub {
if ($n > 0) {
$n + &{ &$f($f, $n - 1) }
} else {
0
}
}
};
&$f($f, @_);
}
my $res = &{ foo 2 };
print $res, "\n";
( run in 1.579 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )