in reply to How do you evaluate a perl command that is in a perl string?

I think that you want to use
eval $string;
not
eval { $string };
The string form of C<eval> will cause the string to be compiled and executed at run-time, capturing the result in $@.

The block form of C<eval> gets compiled only once during the compilation pass of the main program and at run-time the result of executing $string are captured into $@.

Both versions of C<eval> isolate the main program from failures of the code in $string, but only the string-form causes the code to be compiled each time the C<eval> is encountered.

--
zf

Replies are listed 'Best First'.
Re^2: How do you evaluate a perl command that is in a perl string?
by Errto (Vicar) on Jan 20, 2006 at 23:34 UTC
    the result of executing $string are captured into $@.

    The parent is essentially correct but this part is not quite. $@ captures not the "result" of the evaluation, but rather the error message that would be displayed when the eval code died had it not been an eval. If the eval code finishes normally and does not die, then $@ is undefined.