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>