I'm not sure what the while loop is for if you only want to show one page. Here is slightly refactored code with it removed.

sub browse_ten { # work out how many users my @users = glob("users_dir/*"); my $no_of_users = scalar(@users); # calculate how many pages to display my $page_last = ceil($no_of_users / 10) ; # get page to show from param or default 1 my $page_show = param('page') || 1; my $page_prev = $page_show - 1; my $page_next = $page_show + 1; # decide whether to show links print h2("Page $page_show of $page_last"); # optional if ($page_show > 1) { # Show a Previous link print a({href => "?page=$page_prev"},"Previous"); } if ($page_show < $page_last) { # Show a Next link print a({href => "?page=$page_next"},"Next"); } # calc start and end user index number starting # page 1 user start is 0, page 2 is 10 # page 1 end is start + 9 unless on last page my $user_start = ($page_show - 1) * 10; my $user_end = ($page_show < $page_last) ? $user_start + 9 : $no_of_ +users - 1 ; # Show the range of entries. for my $i ($user_start .. $user_end) { my $user_to_show = $users[$i]; # user image my $img_src = "$user_to_show/image.jpg"; unless (-r $img_src){ $img_src = 'blank_profile.jpg'; } print img({src =>$img_src, width=>150, height=> 150 }); # user profile my $profile_filename = "$user_to_show/profile"; if (open my $p, $profile_filename){ my $profile = join '<br/>', <$p>; close $p; print $profile; } else { print "Can not open $profile_filename : $!"; } print br; } }
poj

In reply to Re^3: displaying 10 results per page by poj
in thread displaying 10 results per page by squish20

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.