lexical_subs_recursion_bug.pl 471 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/perl
  2. # Perl bug when using recursion in a `my sub {}` with a parent function.
  3. use 5.014;
  4. use strict;
  5. use warnings;
  6. # Discovered by catb0t:
  7. # https://github.com/catb0t/multifactor/commit/d2a8ad217704182f3b71557aa81a1a62f0ea2414
  8. sub factorial {
  9. my ($n) = @_;
  10. my sub my_func {
  11. my ($n) = @_;
  12. $n <= 1 ? 1 : $n * factorial($n - 1);
  13. }
  14. my_func($n);
  15. }
  16. say factorial(5);
  17. __END__
  18. Can't undef active subroutine at bug.pl line 17.