|
|
| go ahead... be a heretic | |
| PerlMonks |
Re: Uer Perl Variable in txt fileby rovf (Priest) |
| on Aug 06, 2012 at 14:52 UTC ( #985743=note: print w/ replies, xml ) | Need Help?? |
|
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.
-- Ronald Fischer <ynnor@mm.st>
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||