#! /usr/bin/perl -Tw # # -wvh- quick and dirty pager example # use strict; my ($i, $current, $start_limit, $count); my (@hello, %param); # initiate variables (you use db code) $count = 200; $start_limit = 20; $param{'current'} = 46; # <-- test here to simulate page views # initiate array with page contents for ($i = 0; $i <= $count; $i++) { $hello[$i] = "This is record $i"; } ##### cut here ##### $current = $param{'current'}; # <-- do input checks here! $current = 0 if (! $param{'current'}); # optional: round to closest number if input number has been manually # changed to a number not divisable by $start_limit if ($current % $start_limit != 0 && $current != 0) { $current -= $current % $start_limit; } print "$count matches found for your query: \n"; # print pager for ($i = 0; $i <= $count; $i += $start_limit) { if ($i != $current) { print "$i"; } else { print $i; } print " | " if ($i <= ($count - $start_limit)); } print "\n"; # print records for current page for ($i = $current; $i < ($current + $start_limit); $i++) { print $hello[$i] . "\n" if ($i <= $count); }