Hi
I'm having headaches with this.

What I want to do is to create some loop mechanism that allows me to iterate through an @array.
The starting position of the loop is calculated from $offset_value.

$offset_value will be between 0 and (scalar @array) -1

e.g

@array = (qw/ Fred Mark Joe Mary Paul /); $offset_value = 0
Then I would want get the following values returned
Fred Mark Joe Mary Paul
incrementing $offset then I want to get
Paul Fred Mark Joe Mary
Essentially the loop moves the last element to become the first.

What I have tried is the reverse of what I want :(
my @array=(qw/ Fred Mark Joe Mary Paul /); my $offset=0; my $loop=0; while ($loop < 10){ # loop is just to increment the offset value # main loop below for (my $i=0;$i<scalar @array;$i++){ my $r = $i + $offset; if ($r > scalar @array-1){ $r = $r - (scalar @array); } print @array[$r]; } $offset++; $offset=($offset>(scalar @array -1)?0:$offset; $loop++; }
Any Clues/hints/help much appreciated.
Regards
Mark K.

update (broquaint): tidied up formatting


In reply to looping backwards by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.