Although
choroba already warned against using
eval - and he is certainly right with it -, you can consider an
eval-solution, if you understand the risks (and, in particular, if you have control over what goes into your file).
In this case, you could do:
use strict; use warnings;
while(my $line=<FH>) {
print(eval "qq($line)");
}
This solution is much simpler than doing a substitution manually, but never forget: Whoever creates file.txt, can get *any* code being executed by your program; it requires that every variable referenced in the file, exists in the scope of evaluation (and will be replaced); and finally, that, if file.txt contains parentheses, that they are balanced.
--
Ronald Fischer <ynnor@mm.st>