You can use a pager routine like this. You need to have your data in an array to fix the order as suggested. Show say 1-6 represents 0-5 in our array so these are the values we pass back to script in start and end.

my $pages = 25; my $curr_page = 13; my $page_size = 6; my ( $links, $curr_range) = pager("/cgi-bin/script.pl", $pages, $curr_ +page, $page_size); print "Current page array[$curr_page] display range $curr_range\n\n", +$links; sub pager { my ( $link, $total, $curr_page, $page_size ) = @_; $link .= $link =~/\?/ ? "&" : '?'; $curr_page ||= 0; $page_size ||= 6; my @links; my $current_range = 'Unkown'; for ( my $start = 0; $start < $total; $start += $page_size ) { my $end = ($start+$page_size)>$total ? $total : $start+$page_s +ize; my $range = $start+1 == $end ? $start+1 : sprintf "%d-%d", $st +art+1, $end; $end -=1; # we show 1-10 but this is 0-9 in array terms push @links, ($curr_page >= $start and $curr_page <= $end) ? " +$range\n" : qq!<a href="${link}start=$start&end=$end">$range</a>\n!; $current_range = $range if ($curr_page >= $start and $curr_pag +e <= $end); } return (join ' | ', @links) , $current_range; } __DATA__ Current page array[13] display range 13-18 <a href="/cgi-bin/script.pl?start=0&end=5">1-6</a> | <a href="/cgi-bin/script.pl?start=6&end=11">7-12</a> | 13-18 | <a href="/cgi-bin/script.pl?start=18&end=23">19-24</a> | <a href="/cgi-bin/script.pl?start=24&end=24">25</a>

cheers

tachyon


In reply to Re: dividing a hash by sets of $num (aka Paging) by tachyon
in thread dividing a hash by sets of $num 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.