Cagao has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

How can I use Template Toolkit to simply process a string, containing placeholders for variables.

I'm trying this at the mo...

$template->process(\$poo, { network => $obj, }, \$poo) or warn $template->error;


and have tried variation on the above with references, etc.

The string contains things like 'welcome to [% network.name %]'.

Thanks

Replies are listed 'Best First'.
Re: TT to process a string
by moritz (Cardinal) on May 25, 2008 at 16:48 UTC
    #!/perl/bin/perl use strict; use warnings; use Template; my $template = Template->new(); my $str = "some [% foo.bar %] stuff\n"; $template->process(\$str, { foo => { bar => 'cool' }, }) or warn $template->error; __END__ some cool stuff

    Maybe you shouldn't use the same string for both input and output (that appends the result to the template, at least in my tests).

      Okay, thanks.

      that prints the result, but how do I get it back into a variable?
        ignore my last reply, i've got it going into a new variable.
Re: TT to process a string
by rafl (Friar) on May 25, 2008 at 17:03 UTC