Perhaps this has been discussed before, though I searched the archives
before sending this message.

The behavior of the splice vmethod seems to differ slightly from
Perl's splice() in one minor way that I've seen.   One thing I like to
use splice() for is to get elements from a list "n at a time", and
then when there's fewer than n remaining, the loop ends and I deal
with the fewer-than-n items that might remain in the list.

The Perl code that I use for this is:

while(my $item = splice(@mylist, 0, 2)) {

I expected the TT2 version of the code to be:

[% WHILE (item = mylist.splice(0,2)) %]

I was surprised to see that this did not behave as I have come to
expect from splice(), so some time ago I added a line to Stash.pm,
according to this patch:

Index: lib/Template/Stash.pm
===================================================================
330a331
        return '' unless scalar @{$list};

While there may be other ways of dealing with this situation in TT2 as
it is currently, and I'm open to those, my point is that it appears
that the vmethod and the Perl function differ slightly and the
documentation suggests that the vmethod intends to mirror the
function's behavior.

Or perhaps I misunderstand them both :)   Please advise.

Regards,
John

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to