You need to keep track of two things: where to start, and how many to show.

First set $start to one unless we're getting a param.

unless(param('start')){ $start = 1 }
Then use two counters to track where to start and how many to process.
for(@array){ $c++; # count all items if($c >= $start){ # if $c count is = or greater than where to star +t $d++; # count items that match first test unless($d > $show){ # unless $d count is greater than how many + to show print # or whatever } } }
Then calculate the 'previous n' and 'next n' links.
$previous = ($start-$show); unless($previous < 1){ # unless we're already at the beginning print qq~<a href="$url?start=$previous&show=$show"> Previous $show</a>~; } $next = ($start+$show); unless($next > $c){ # unless we're already at the end print qq~<a href="$url?start=$next&show=$show"> Next $show</a>~; }

In reply to Re: last 10 ... next 10? by epoptai
in thread last 10 ... next 10? 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.