in reply to sending a scalar to the interpreter as a command
there are ways to send variables to the interpreter as commands
Yes. eval (the quotish version).
my $code = 'print qq{Hello world!\n};'; eval $code;
Or, since the value returned is the value of the last expression evaluated:
my $code = '1+1'; my $result = eval $code; print $result, "\n";
I feel this answer, while probably accurate, could be a sub-optimal solution to your real problem. Many languages that are considered quite powerful provide no equivalent to eval, and the odds are good that most of those languages could solve the problem you're working on without eval. It might be the case that if you back up a step or two, and present the actual problem you're solving, rather than how you think you would like to solve it, you might get a better answer. eval is useful, but it's one of those things that usually can be avoided for the better.
Dave
|
|---|