A TT2 curiosity: pop does what it always does—but when I have template code embedded in HTML, it also inserts the popped value into my HTML, causing it to be displayed on screen. For example,
[% list = [1, 2, 3] %] [% list.pop %]
removes "3" from the list and inserts it into my HTML. I don't want it to insert anything into my HTML. I just want the list to contain one less value. I see a lot of ways to do this, e.g.,
[% list = [1, 2, 3] %] [% p = list.pop %]
but I don't like any of them. The example I've provided is unsatisfactory because I've no use for the popped value. I would use something like
[% list = [1, 2, 3] %] [% list = list.slice(0,1) %]
but I won't always know the length of the list in advance. Isn't there a simple standard way to do what I want?

Many thanks. I searched the TT mailing list but couldn't find anything speaking to this.

In reply to Template Toolkit: silencing pop() and the other list virtual methods by jbullock35

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.