Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by larsen (Parson)
on Aug 06, 2003 at 12:23 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://281358]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found