>>>>> "Franco" == Franco Bagnoli <[EMAIL PROTECTED]> writes:
Franco> I often deal with structured arrays (LoL), say
Franco> [%a = [0, [1,2],[3,4], [4,5,6]] %]
Franco> and I need to print them in some form, sometimes just flattened.
Franco> Join doesn't do the job, and neither merge (it is undocumented, isn't
Franco> it?)
Franco> I wrote a generalization of join (I need a better name than jj)
here's a pure-TT implementation that might be an interesting start:
[%-
BLOCK mm;
DEFAULT separator = " ";
DEFAULT list_prefix = "";
DEFAULT list_suffix = "";
mylist = list.list;
IF mylist.size == 0;
ELSIF mylist.size == 1;
mylist.0;
ELSE;
FOREACH item = mylist;
list_prefix IF loop.first;
INCLUDE mm list = item;
IF loop.last; list_suffix; ELSE; separator; END;
END;
END;
END;
-%]
And now for the tests:
[% INCLUDE mm
list = ["hello", ["world", "we", ["do", "see"], "really"], "smartly"]
%]
[% INCLUDE mm
list = ["hello", ["world", "we", ["do", "see"], "really"], "smartly"]
separator = ","
%]
[% INCLUDE mm
list = ["hello", ["world", "we", ["do", "see"], "really"], "smartly"]
separator = ","
list_prefix = "("
list_suffix = ")"
%]
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates