The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

#!/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 FATAL => 'uninitialized';
# "This token is only available under use v5.16 or the "current_sub" feature"
use v5.16;
sub foo {
my $f = sub {
my ($n) = @_;
my $f = __SUB__;
sub {
if ($n > 0) {
$n + &{ &$f($n - 1) }
} else {
0
}
}
};
goto &$f
}
my $res = &{ foo 2 };
print $res, "\n";