Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-06-21 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.