# http://somesite.com/cgi-bin/display.pl?current_page=12 # display.pl #!/usr/bin/perl -w use strict; use CGI; #use DBI; my $SCRIPT = 'http://somesite.com/cgi-bin/display.pl'; my $RECS_PER_PAGE = 10; my $q = new CGI; print $q->header; #my $dbh = DBI->connect( etc.... ); if ( $q->param('start')) { display_this_db_section( $q->param('start'), $q->param('end'), $q->param('current_page') ); } else { my $count = get_record_count(); my $page = $q->param('current_page') || 1; my $html = get_current_page($page); $html .= generate_links($count, $page ); print $html; } exit 0; #### SUBS #### sub display_this_db_section { my ($start, $end, $current_page ) = @_; $current_page ||= $start; my $count = get_record_count; die_nice ( 'Invalid' ) if $start > $count or $start < 1 or $end > $count or $end < 1 or $start > $end or $start > $current_page or $end < $current_page; print "

Here is $current_page of $start-$end

\n"; print "

", generate_links( $count, $current_page ) # blah } sub generate_links { my ($count, $current_page ) = @_; my $html = ''; for ( my $start = 1; $start <= $count; $start += $RECS_PER_PAGE ) { my $end = $start + $RECS_PER_PAGE -1; $end = $count if $end > $count; $html .= ( $start <= $current_page and $current_page <= $end ) ? "[$start-$end] " : qq![$start-$end] \n!; } return $html; } sub get_current_page { my $page = shift; # validate page, get data, format, return html return "

This is the content for page $page

\n"; } sub get_record_count { # get count of records, simulate here return 42; } sub die_nice { print shift and exit }