PDA

View Full Version : splitting output of foreach into more than one page


bazz
01-17-2006, 08:02 PM
Hi,

My foreach loop outputs more than ten items. I want to place about 10 items on each page with a row of hyperlinks page2 page 3 etc. The as you click each hyperlink, the script could re-run outputting the data as appropriate. How should I try to go about this please?

I think I can see hashes as the solution but I'm not sure and, still, have a mental block with them. :(


foreach (sort @listOfDirs ) {

if ($distance <= $radius) {
# /// end showing radius /// #


# /// output the html /// #
$baseBusinessName1st =~ s/-/ /g;
$rounded = sprintf("%.2f", $distance);
$nearbyBusinesscompiler = join('_', $nearbyBusinessName,$nearbyBusinessType,$nearbyBusinessSubType, $nearbyBusinessCat,$nearbyBusinessLocalRegion,$nearbyBusinessCounty,$nearbyBusinessGrid, $nearbyBusinessPostCode,$nearbyBusinessGroupName);
$nearbyBusinessName =~ s/-/ /g;
$nearbyBusinessCat =~ s/-/ /g;
$baseBusinessName =~ s/-/ /g;

unless ( $category eq $nearbyBusinessType && $subCategory eq $nearbyBusinessSubType ) {
# do nothing
} else {
print <<EOF;
<dt>$nearbyBusinessName</a></dt>
<dd>Distance: $rounded Km $NorthSouth$WestEast of $baseBusinessName</dd>
<dd>Classification: $nearbyBusinessCat</dd>

EOF
}





Any tips appreciated

Bazz

FishMonger
01-18-2006, 04:42 PM
I have not used them, but there are several paging modules available on cpan. Most are a subclass of Data::Page

http://search.cpan.org/~lbrocard/Data-Page-2.00/lib/Data/Page.pm
http://search.cpan.org/~kazeburo/Data-Page-Navigation-0.02/lib/Data/Page/Navigation.pm
http://search.cpan.org/~berikv/Data-Page-Set-0.04/lib/Data/Page/Set.pm
http://search.cpan.org/~knew/Data-SpreadPagination-0.1.2/lib/Data/SpreadPagination.pm