squish20 has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to design a dating website for a school assignment given a synthetic data set. I was trying to display 10 profiles per page with links to the next and previous page. I've tried a whole heap of things but it always seem to get some sort of error on the href lines. I was hoping someone could point out where i went wrong. Also, Perl seems to complain that i have unmatched curly braces when i had the right number of braces. Removing the ending brace for the while loop and the subroutine seemed to have fixed that but now i'm actually missing two braces! Here's my subroutine:
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 pa +ges to display while ($page le $pages_required) { my $start = ($page - 1) * 10; # index to begin display +ing 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 "<a href=\"engcupid.cgi?page=" + ($page +- 1) + "\">Previous</a>"; } if (scalar(@users) > $end) { # There's more entries after what's being show +n print "<a href=>\"engcupid.cgi?page=" + ($page + + 1) + "\">Next</a>"; } # 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 op +en $profile_filename: $!\n"; if(-r "$user_to_show/image.jpg"){ print img({src=>"$user_to_show/image.j +pg", width =>150, height=>$150}); } else { print img({src=>"blank_profile.jpg", w +idth=>150, height=>150}); } $profile = join '<br>', <$p>; $profile .= "<br>"; close $p; print $profile; } $page = $page+1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: displaying 10 results per page
by kcott (Archbishop) on May 26, 2012 at 05:12 UTC | |
by squish20 (Initiate) on May 26, 2012 at 07:18 UTC | |
by ww (Archbishop) on May 26, 2012 at 11:32 UTC | |
by Anonymous Monk on May 26, 2012 at 08:36 UTC | |
by poj (Abbot) on May 27, 2012 at 14:19 UTC | |
|
Re: displaying 10 results per page
by CountZero (Bishop) on May 26, 2012 at 19:32 UTC |