Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Substituting Variables while reading text file

by aitap (Curate)
on Aug 07, 2014 at 07:21 UTC ( #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
Node Status?
node history
Node Type: note [id://1096559]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-07-21 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (442 votes). Check out past polls.

    Notices?