sub browse_ten { my $page = 1; # intialise number of pages my @users = glob("users_dir/*); #entire array of all the user files to be displayed. my $pages_required= ceil(($#users)/10); #calculate how many pages to display while ($page le $pages_required) { my $start = ($page - 1) * 10; # index to begin displaying them my $end = $start + 10; # show 10 results per page $end = scalar(@users) if $end > scalar(@users); # cap the end # whether to show links if ($start > 0) { # Show a Previous link print "Previous"; } if (scalar(@users) > $end) { # There's more entries after what's being shown print "\"engcupid.cgi?page=" + ($page + 1) + "\">Next"; } # Show the range of entries. for (my $i = $start; $i < $end; $i++) { my $user_to_show = $users[$i]; $profile_filename = "$user_to_show/profile"; open $p, "$profile_filename" or die "cannot open $profile_filename: $!\n"; if(-r "$user_to_show/image.jpg"){ print img({src=>"$user_to_show/image.jpg", width =>150, height=>$150}); } else { print img({src=>"blank_profile.jpg", width=>150, height=>150}); } $profile = join '
', <$p>; $profile .= "
"; close $p; print $profile; } $page = $page+1;