Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Template::Toolkit: better way to generate variable names?

by larsen (Parson)
on Aug 06, 2003 at 12:23 UTC ( #281358=note: print w/ replies, xml ) Need Help??


in reply to Template::Toolkit: better way to generate variable names?

Did you try this?

[% foo_1 = 'value1' foo_2 = 'value2' foo_3 = 'value3' foo_4 = 'value4' foo_5 = 'value5' %] [% FOREACH n = [ 1 .. 5 ] %] [% 'foo_' _ n %] is [% ${ "foo_$n" } %] [% END %]
Anyway, apply here the usual arguments against variable variable names. Use a hash or an array, if you can.

Update: I misread the question. See geektron's reply.


Comment on Re: Template::Toolkit: better way to generate variable names?
Download Code
Re: Re: Template::Toolkit: better way to generate variable names?
by geektron (Curate) on Aug 06, 2003 at 13:01 UTC
    i really don't need a hash or array in this case.

    if it were straight perl, i would have done:

    foreach my $counterVar ( 1 .. 5 ) { $foo = "string" . $counterVar; }
    the issue was with the TT meta-language, really. it *can* get a bit odd...

    what i *do* need out of the suggestion is:

    [% SET FOO = 'string' _$n %]
    -- i do need to double-check the underscore location ... --

    after reading the previous reply, the connection between TT's meta-language and 'core perl' kicked in.

Re: Re: Template::Toolkit: better way to generate variable names?
by geektron (Curate) on Aug 07, 2003 at 20:04 UTC
    [% 'foo_' _ n %]
    this is exactly what i needed. many thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2015-07-04 11:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls