Hi
I'm pretty new to perl and I am currently trying to do an assignment for school which involves us creating a dating website. This requires me to present 10 profiles per page with links to the next and the previous page. This is the subroutine i wrote to handle this:
It previously kept giving me the error that it :Can't modify constant item in scalar assignment at ./trial3.cgi line 37, near ""\">Previous</a>";"
I tried to fix that by replacing the '=' with '=>' in the href lines.
It still gives me a syntax error on those lines which i dont quite seem to be able to fix.
Also there are 2 missing braces in the function coz perl is being silly and complains that there are extra curly braces when i put the right number of braces in
I was hoping someone could help me figure out what's wrong with that statement.
I'm pretty new to perl and I am currently trying to do an assignment for school which involves us creating a dating website. This requires me to present 10 profiles per page with links to the next and the previous page. This is the subroutine i wrote to handle this:
Perl:
sub browse_ten {
my $page = 1; # intialise number of pages
my @users = glob("user_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 "<a href=>\"engcupid.cgi?page=" + ($page - 1) + "\">Previous</a>";
}
if (scalar(@users) > $end) {
# There's more entries after what's being shown
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 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 '<br>', <$p>; $profile .= "<br>";
close $p;
print $profile;
}
$page = $page+1;
It previously kept giving me the error that it :Can't modify constant item in scalar assignment at ./trial3.cgi line 37, near ""\">Previous</a>";"
I tried to fix that by replacing the '=' with '=>' in the href lines.
It still gives me a syntax error on those lines which i dont quite seem to be able to fix.
Also there are 2 missing braces in the function coz perl is being silly and complains that there are extra curly braces when i put the right number of braces in
I was hoping someone could help me figure out what's wrong with that statement.