Find limit of recursion

Maximum recursion depth is memory dependent. Values in excess of 1 million are easily achieved.

my $x = 0;
recurse;

sub recurse () {
   ++$x;
   say $x if $x %% 1_000_000;   
   recurse;
}

When manually terminated memory use was on the order of 4Gb:

1000000
2000000
3000000
4000000
5000000
6000000
7000000
8000000
9000000
10000000
^C

Last updated