in reply to Substituting Variables while reading text file
String::Interpolate might be useful in this task. If you move your variables to be interpolated to a hash, you will be able to do it yourself, like this:
(untested).my %variables = ( ... ); ...; while (<FILE>) { s/\$(\w+)/$variables{$1}/eg; print; }
What you are writing looks like a templating engine. Unless it's a "homework" question, it might be useful to look at Text::Template, Mason and Template.
|
|---|