"first" as a variable

Ben Bullock <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <CAN5Y6m_Rn6MZc6OR0rgZGD0g1Pqgq1VyffpJMoq-qfrF3G1YRQ@mail.gmail.com>
In my template,

[% FOR name IN name_list %]
[%- n = name.0 | lower %]
[%- IF category2article.$n %]
[% cats = category2article.$n -%]
/* [% n %] */
article_t cat_[% loop.count - 1 %][] = {
[%- cats.join (", ") -%], -1};
[%- END %]
[%- END %]

In the usual case, this produces

/* event */
article_t cat_748[] = {419, 1346, -1};

But when "name_list" contains the word "first",

/* first */
article_t cat_775[] = {HASH(0x2862d2d0), -1};

This seems to be some kind of mismatch between the template toolkit's
"first" keyword and the action of the variable $n. I am not sure if
this is the expected behaviour, but if it is, how should I have
phrased category2article.$n to avoid this?

At the moment I have just written a trap for it:

[% FOR name IN name_list %]
[%- n = name.0 | lower %]
[%- IF n != 'first' -%]
[%- IF category2article.$n %]
[% cats = category2article.$n -%]
/* [% n %] */
article_t cat_[% loop.count - 1 %][] = {
[%- cats.join (", ") -%], -1};
[%- END %]
[%- END # first trap -%]
[%- END %]

This works because I didn't need "first" as a keyword, but it's a bit
worrying that I have to do this and I suspect a bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.