in reply to Format and Join an Array in a Template
TT has some nice meta information included in all loops (size, max, index, count, first, last, prev, next). I think this is much easier to read than the slice stuff-
[% FOR item IN my_stuff %] .[% item %]([% item %])[% "," UNLESS loop.last %] [% END %]
You can also bake this stuff into your templates if you want.
use Template::Stash; $Template::Stash::LIST_OPS->{my_weird_join} = sub { join(",\n", map { "$_.($_)" } @{ +shift || [] }; }; # then... [% my_stuff.my_weird_join %]
Not tested but looks right.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Format and Join an Array in a Template
by mscharrer (Hermit) on Jun 20, 2009 at 09:32 UTC | |
by Your Mother (Archbishop) on Jun 20, 2009 at 19:49 UTC | |
|
Re^2: Format and Join an Array in a Template
by mscharrer (Hermit) on Jun 22, 2009 at 14:51 UTC |