Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Substituting Variables while reading text file

by aitap (Curate)
on Aug 07, 2014 at 07:21 UTC ( [id://1096559]=note: print w/replies, xml ) Need Help??


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:

my %variables = ( ... ); ...; while (<FILE>) { s/\$(\w+)/$variables{$1}/eg; print; }
(untested).

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1096559]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found