[Templates] assigning to scalar passed as scalar reference

Jason Gottshall jgottshall at capwiz.com
Tue Jul 8 20:48:51 BST 2008


Lee.M wrote:
> I want to do this:
> 
>   my $var = '';
> 
>    $tt->process($tmplt, { var => \$var}, $out);
> 
>    print "var is now $var\n"; # var is now new value
> 
> and allow the template to set its value

Pass a known hashref of template variables, instead of an anonymous one,
and you can refer to it later:

   my %variables = ();
   $variables{var} = '';

   $tt->process($tmplt, \%variables, $out);

   # $tmplt contains:
   # [% var = 'new value' %]

   print "var is now $variables{var}\n"; # var is now 'new value'

HTH,
Jason




More information about the templates mailing list