in reply to eval strings non reentrant?

I will do it this way:

use strict; use warnings; my $e = "foo(0)"; eval $e; sub foo { my $i = shift; print "$i foo\n"; if ($i < 10){ $i++; print "calling foo\n"; foo($i); } }

Other than the direct issue others already pointed out, there is two other style things:

  1. $i is not well scoped. You never define a variable with a scope even slightly bigger than its need. In case, $i shall be defined within the foo() function, and be passed as a parameter when it calls itself.
  2. It might seems okay for a demo, but define a sub in a string is not quite a good idea.

Your guess that it has something to do with multithreading is... as multithreading will not help in this case.