[Templates] slice behavior

apv ashley@sedition.com
Sat, 11 Feb 2006 12:40:33 -0800


So, both these from the docs work fine:

     [% first_three = list.slice(0,2) %]
     [% last_three  = list.slice(-3, -1) %]

But this doesn't:

     [% the_rest = list.slice(3, -1) %]

Might be nice if it did though it's not the real perl behavior.
Not saying it's needed or even a good idea, just throwing it out
there b/c I like the idiom.

So, the "$to" line (Stash.pm):
     'slice' => sub {
         my ($list, $from, $to) = @_;
         $from ||= 0;
         $to = $#$list unless defined $to;
         return [ @$list[$from..$to] ];
     },

becomes...? maybe? (untested)
         $to = @$list + $to if ( $to < 0 and $from > 0 );
         $to = $#$list unless defined $to;


-Ashley