I am thinking about making clear and short script to rotate array, let's say:
input: @list = (1 .. 20); $start = 10; #starting position $values = 10; #how much values in result
how to get output: @result = ( 5, 6, 7, 8, 9, 11, 12, 13, 14, 15 ); #10 values (I don't want $start in @result)
Did you suddenly change $start to 4?
ofcoure script should work with overlapping too: @list = (1 .. 20); $start = 18; $items = 10;
output: @result = ( 13, 14, 15, 16, 17, 19, 20, 1, 2, 3 ); #10 values
I fail to see how that would be the result of $start = 18.
Anyway, even if it's unclear what you mean by start position, something like this may be what you want:
sub rotate {
my @list = @{ +shift };
my ($start, $values) = @_;
unshift @list, splice(@list, $start);
@list[ 0 .. $values-1 ]
}my @result = rotate( [EMAIL PROTECTED], $start, $values );
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
