in reply to Uer Perl Variable in txt file
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:
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.use strict; use warnings; while(my $line=<FH>) { print(eval "qq($line)"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Uer Perl Variable in txt file
by vinaybond (Novice) on Aug 07, 2012 at 06:13 UTC | |
by Anonymous Monk on Aug 07, 2012 at 08:44 UTC | |
|
Re^2: Uer Perl Variable in txt file
by Anonymous Monk on Aug 06, 2012 at 20:06 UTC | |
by rovf (Priest) on Aug 07, 2012 at 08:19 UTC |