Mark
Thanks for your help with this, I'm not sure I understand exactly what I was
doing wrong because I was getting the right value in val when I printed it
out, it just wasn't getting put onto the list properly. Also, if I use a
push (thanks Andy - didn't know you could do that) onto the list it does
work using exactly the same loop:
[%- FOREACH val = list_string.split(';') -%]
[%- mylist.push(val) -%]
[%# mylist.$counter = val -%]
[%#- counter = counter + 1 -%]
[% END -%]
Does this mean that I cannot use [% mylist.$counter = val -%] as a way of
populating a list?
- at least I don't think there is a problem with split now!
Thanks for the help
Colin
-----Original Message-----
From: Mark Mills [mailto:[EMAIL PROTECTED]]
Sent: 2002-mm-29 17:29
To: Johnson Colin (KnowledgePool); [EMAIL PROTECTED]
Subject: RE: [Templates] Problem with split (...maybe)
You aren't using split wrong, you are using "val" wrong. =) You are
suffering from the classic error of putting the same reference into an array
with each pass through your FOREACH loop.
I'd recommend you do:
[% mylist = list_string.split(';') -%]
[% FOREACH val = mylist %]
data[[% val %]] [[% loop.count %]]
[% END -%]
--mark
> I think I may have found a bug when using the split function because I
> believe that I am using it according to theTemplate Documentation, but
> I could be doing something really stupid here. Unfortunately I do not
> have the knowledge of the Template code to find out if it really is a
> bug - I have checked the split function in Stash.pm and this is
> returning an array correctly and this is about as far as I can go. If
> anyone can see something really daft in this code, let me know.
>
> [%- FOREACH val = list_string.split(';') -%]
> data[[% val %]] [[% counter %]]
> [% mylist.$counter = val -%]
> [%- counter = counter + 1 -%]
> [% END -%]
>
> I can, however, create an array correctly like this...
> [% mylist_too = list_string.split(';') -%]
> If anyone can see anything wrong in the code, it would be much
> appreciated.