Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Persistant variables in TT2

by davidrw (Prior)
on May 10, 2005 at 14:47 UTC ( [id://455597]=note: print w/replies, xml ) Need Help??


in reply to Persistant variables in TT2

instead of passing in the scalar 'a', pass in a hashref with your data, and the changes will persist:
use Template; my $vars = { a => 0 }; my $tt2 = Template->new(); my $template = "[% SET data.a=data.a+1 %] A is now [% data.a %]\n"; $tt2->process( \$template, { data => $vars } ) for 1..5;
Update: My guess, based just on the behavior seen in my post and the OP, is that TT passes the data by value. So in the OP, the 'a' that gets modified isn't the real 'a'. In my post, we're not modifying the value (address) of 'data', but are deferencing it and then changing values, so they appear to persist.

Replies are listed 'Best First'.
Re^2: Persistant variables in TT2
by Molt (Chaplain) on May 10, 2005 at 14:56 UTC

    Thanks for that, it does seem to work quite nicely. I was admittedly hoping for some way to make it 'just work' but I guess this will serve my purposes fine.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-19 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found