Re: How to write a macro that changes a scalar variable

Chad Wallace <[email protected]> Tue, 21 Oct 2014 12:10:16 -0700
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Organization The Lodging Company
Message-ID <[email protected]>
On Tue, 21 Oct 2014 11:27:31 +0200 (CEST)
"Kiss Gabor (Bitman)" <kissg-8/[email protected]> wrote:

> I do understand what happens but I have no idea how to modify
> the code. Actually I would need a macro that acts like a subroutine
> and returns a scalar value but I guess this is not possible.
> Therefore I tried to modify named parameters but they seems to be
> localised too.

You can return a scalar (but not an array or hash ref) in
the macro's output, and capture it in a variable using SET.


$ tpage
[% MACRO seven BLOCK; "7"; END %]
! starting...
[% SET var = 3 %]
! var before = [% var %]
[% SET var = seven() %]
! var after = [% var %] (wanted 7 here)
[%####################################%]

! starting...

! var before = 3

! var after = 7 (wanted 7 here)


-- 

C. Chad Wallace, B.Sc.
The Lodging Company
http://www.lodgingcompany.com/
OpenPGP Public Key ID: 0x262208A0