in reply to Dynamic variable naming in Template Toolkit

http://www.template-toolkit.org/docs/plain/Manual/Variables.html#Variable_Interpolation
  • Comment on Re: Dynamic variable naming in Template Toolkit

Replies are listed 'Best First'.
Re^2: Dynamic variable naming in Template Toolkit
by agianni (Hermit) on May 31, 2007 at 15:10 UTC

    Right, I've read it. What I want to be able to do based on my understanding of the docs is something like:

    [% var_name = 'foo'; $var_name = 'bar'; # I wish $foo would eq 'bar' but it doesn't %]

    but my understanding is that:

    [% var_name = 'foo' %]

    is the same as:

    [% $var_name = 'foo' %]

    Right? So far I'm thinking that I can't achieve what I want. Fortunately this is Perl, so there's always another way :)

    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'
      Try ${var_name} = 'bar', and if that doesn't work, ask on the TT mailing list. I think TT supports this.

        That did it, in fact the code I posted above:

        [% var = 'foo'; $var = 'bar'; # now $foo eq 'bar'! %]

        actually works without the braces, I found a typo in my code :P

        perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'