in reply to No recursion depth limit?
G'day Yary,
"I have this memory of Perl limiting how deep subroutine recursion could go, ..."
Perl only warns when a certain recursion depth is reached; it doesn't prevent you from recursing deeper.
"... but the following test suggests not:"
If you ask for warnings, you get them:
$ perl -E 'sub f{say $_[0] unless $_[0] % 10000;exit if $_[0] > 30000; +f($_[0]+1)};f(1)' 10000 20000 30000 $ perl -wE 'sub f{say $_[0] unless $_[0] % 10000;exit if $_[0] > 30000 +;f($_[0]+1)};f(1)' Deep recursion on subroutine "main::f" at -e line 1. 10000 20000 30000
"Just curious if there was a recursion limit, ..."
The limit is 100, i.e. on the 100th recursion, a warning is emitted.
$ perl -wE 'sub f{say $_[0] unless $_[0] % 33;exit if $_[0] >= 99;f($_ +[0]+1)};f(1)' 33 66 99 ken@ganymede: ~/tmp $ perl -wE 'sub f{say $_[0] unless $_[0] % 33;exit if $_[0] >= 100;f($ +_[0]+1)};f(1)' 33 66 99 Deep recursion on subroutine "main::f" at -e line 1.
Search for "Deep recursion on subroutine" in perldiag for more details and additional information.
Also, if you're using the warnings pragma, which I strongly recommend, you can selectively turn off warning messages.
— Ken
|
|---|