From: "Ing. Branislav Gerzo" <[EMAIL PROTECTED]>
> 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

many (taky si to furt pletu)

> how to get output:
> @result = ( 5, 6, 7, 8, 9, 11, 12, 13, 14, 15 ); #10 values
> (I don't want $start in @result)
> 
> 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

Assuming $values does not get bigger than the number of items in the 
list and $start is always <= the number of items in the list:

        @list = (@list, @list);
        @result = (
                @list[($start-$values/2-1) .. ($start-2)],
                @list[($start) .. ($start+$values/2-1)]
        );

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to