Hi,
I'm trying to generate a file using the
Template module.
I have an array of names and need to produce a comma separated list where each name appears twice in the format ".$name($name)":
@myarray = qw(A B C D E);
should produce:
.A(A),
.B(B),
.C(C),
.D(D),
.E(E)
Please note that the last line does not end in a comma.
If the problem with the last trailing comma would not exits I simple could use
FOREACH:
[% FOREACH n in names %]
.[% n %]([% n %]),
[%- END %]
Also I know about the possibility to use
.join():
[% names.join(",\n") %]
which does not allow me to use the names twice.
I tried some combinations and checked the manual but could not find a solution yet. Can someone with more experience with Template point me in the right direction?
Thanks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.