Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re-Interpolating a Scalar (a string)

by jeffa (Bishop)
on Jul 29, 2005 at 18:49 UTC ( [id://479508]=note: print w/replies, xml ) Need Help??


in reply to Re-Interpolating a Scalar (a string)

Use one of the various templating modules from CPAN:

  • Text::Template
    use strict; use warnings; use Text::Template; my $template = Text::Template->new( TYPE => 'STRING', SOURCE => 'fred has {$color} eyes' ); our $color = 'blue'; print $template->fill_in;
  • HTML::Template
    use strict; use warnings; use HTML::Template; my $data = 'fred has <tmpl_var color> eyes'; my $template = HTML::Template->new( scalarref => \$data, ); $template->param( color => 'brown', ); print $template->output;
  • Template
    use strict; use warnings; use Template; my $data = 'fred has [% color %] eyes'; my $vars = { color => 'blue', }; my $tt = Template->new; $tt->process(\$data, $vars) || die $tt->error;

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-29 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found