in reply to Re^2: Dynamically Creating a Code reference
in thread Dynamically Creating a Code reference

I think you did something wrong, perhaps you used single quotes instead of double quotes. As it is in my code, the string is inserted in the sub definition before it is evalled. Try this:
$code = 'print "I love perl\n";'; $coderef = eval "sub { $code }"; $coderef->(); print "Don't believe me?\n"; $coderef->();
Result:
I love perl Don't believe me? I love perl

Replies are listed 'Best First'.
Re^4: Dynamically Creating a Code reference
by Herkum (Parson) on Jun 16, 2006 at 13:34 UTC

    I misread the code sample you gave me and the code that I posted, I did test, and it did exactly what I said. Which was totally different from what you stated.

    You are right, I am wrong this does work.