Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: dividing a hash by sets of $num (aka Paging)

by tachyon (Chancellor)
on Mar 14, 2004 at 13:46 UTC ( [id://336489]=note: print w/replies, xml ) Need Help??


in reply to dividing a hash by sets of $num

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://336489]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found