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

Hi, I have a little block which looks something like this in my template:
[%a = 1%] [%b = ''%] [%PERL%] my $test = "[%a%]"; $test += 1; [%END%]

My question is how do I assign the value of $test to template variable "%b%" ?

Replies are listed 'Best First'.
Re: Template Toolkit Embedded Perl
by arkturuz (Curate) on Nov 10, 2008 at 12:11 UTC
    From the documentation:

    [%a = 1%] [%b = ''%] [%PERL%] my $test = "[%a%]"; $test += 1; $stash->set('b', $test); [%END%]
    update: added code.
Re: Template Toolkit Embedded Perl
by Mr. Muskrat (Canon) on Nov 10, 2008 at 18:48 UTC

    I assume that your real template is more complicated than that but if it isn't you could also do something simple like this:

    [% a = 1 %] [% b = a + 1 # or "$a" + 1 %]