The slice() list VMethod suggests you can use negative indices to count
"backwards" from the end of the list. It doesn't quite work as expected
if one index is positive but the other negative. For example, I wanted
all but the first and last elements:

  list.slice(1, -1)

This in fact always returns an empty list.

This can be fixed by:

--- VMethods.pm 2008-03-14 00:37:37.000000000 +0000
+++ VMethods.pm.new     2008-03-14 00:37:04.000000000 +0000
@@ -508,6 +508,8 @@
     my ($list, $from, $to) = @_;
     $from ||= 0;
     $to = $#$list unless defined $to;
+    $from += @$list if $from < 0;
+    $to   += @$list if $to   < 0;
     return [ @$list[$from..$to] ];
 }

-- 
Paul "LeoNerd" Evans

[EMAIL PROTECTED]
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

Attachment: signature.asc
Description: Digital signature

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to