Maybe use this instead, which will always make lista a list no matter if it's a
scalar or list?:
[% FOREACH item = lista.list.merge(listb) %]
Disclaimer: I didn't try this.
-- Josh
Geoffrey Young wrote:
hi all...
I was bitten by a merge feature recently. it looked something like this
Template->new->process(\*DATA, { lista => undef,
listb => [ qw(one two) ] });
__DATA__
[% FOREACH item = lista.merge(listb) %]
found [% item %]
[% END %]
to me (the infrequent TT user) I was expecting merge to behave something
equivalent to
@newlist = (@lista, @listb);
but will accept that my expectations are wrong :) changing lista to [] had
the desired effect, but it felt a bit odd to me - what I was trying to do
was concat N number of lists together with some being undef, which works
fine as long as the _first_ list isn't undef.
anyway, I patched vmeth.t to illustrate the behavior but I wasn't able to
quickly pin down a culprit - the merge routine in Stash.pm seems to be
returning the correct list, so the issue rests someplace deeper it seems.
just FYI in case anyone cares.
--Geoff
------------------------------------------------------------------------
--- t/vmeth.t 2003-07-24 08:13:03.000000000 -0400
+++ t/vmeth.t.new 2005-10-25 19:25:44.040800033 -0400
@@ -414,6 +414,29 @@
'1' '2' '3' '4' '5' '6' '7' '8' '9' '0'
-- test --
+[% list_one;
+ list_two = [ 4 5 6 ];
+ "'$l' " FOREACH l = list_one.merge(list_two) %]
+-- expect --
+'4' '5' '6'
+
+-- test --
+[% list_one = [ ];
+ list_two = [ 4 5 6 ];
+ "'$l' " FOREACH l = list_one.merge(list_two) %]
+-- expect --
+'4' '5' '6'
+
+-- test --
+[% list_one = [ 1 2 3 ];
+ list_two;
+ list_three = [ 4 5 6 ];
+ "'$l' " FOREACH l = list_one.merge(list_two, list_three) %]
+-- expect --
+'1' '2' '3' '4' '5' '6'
+
+
+-- test --
[% list_one = [ 1 2 3 4 5 ] -%]
a: [% list_one.splice.join(', ') %]
b: [% list_one.size ? list_one.join(', ') : 'empty list' %]
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates