cgi_err has asked for the wisdom of the Perl Monks concerning the following question:

just say if i have a page with 800 downloads on it, 1 line per download. and i want to only show 100 downloads per page, presume there is 40 of these html documents with 800 downloads on each page and i already have written a perl program which reads all the dirs contents and prints the files/links out to the html pages. now all i have to do is make the program split them up into smaller pieces, the main problems is, if i can even get it to split them up how do i put links on every single pages i.e. Page1.htm Page2.htm Page3.htm several links on each page. oviously it would take a long time to manually do it and maintain it for when there updated so thats why i want to ad it into the perl script which reads the dirs and makes the html to start off with. :) any ideas or thoughts all welcomed

this is the theory i thought would work.

# blah blah for ($i = 0; $i < 27; $i++){ @alfabet = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o +","p","q","r","s","t","u","v","w","x","y","z","numbers"); the 27 = the number of pages, the alfabet, these are the dirs to get s +canned. # blah blah opendir (DIR,"$dirpath/$page/"); @DIR = readdir(DIR); closedir (DIR); # blah blah print file qq~ $list ~;
ok so i was thinking maybe i could use something like this.
$number="$number"+"100"; # somewhere in there # can anyone tell me how to do it?
cheers.

Edit Masem 2001-11-05 - CODE tags

Replies are listed 'Best First'.
auto cutting, pseudocode.
by clintp (Curate) on Nov 06, 2001 at 02:01 UTC
    This assumes that the list doesn't change frequently, or if it does you don't care about the occasional bad link or miss. Pseudocode:
    Get the list of files in @list
    Set the maximum number per page in $max
    Determine from the CGI param "page", which page we're
         supposed to display.  Default to 0 if not set.
    Divide the list by $max, round up.  Save this in $chunk.
    Take the section of @list from $max*$page to
        ($max*($page+1)-1) or the end, whichever.
    Display the list of things from the previous step.
    At the end of the page, make links back to this script 
        for each of 0 to $chunk.  Bake page=$chunk into each
        of the link urls.  These will display various pages
        of the list.
    
Re: auto cutting or setting page size limite per lines etc
by mr_mischief (Monsignor) on Nov 06, 2001 at 01:59 UTC
    The following assumes, of course, that you're getting @link from somewhere before this code executes.

    It also assumes each link is already formatted as an anchor or link tag and has the proper HTML formatting around it, but that's easy enough to work into the code.

    Finally, it assumes you want your 'next', 'previous', and per-page links links at the top. That can be changed, but it makes the first page a special case if you move it elsewhere.

    The current page includes a live link to itself, because it's just easier that way. It also could use modulo to only put a numbered link for every five pages or every ten (or whatever), but it doesn't. This is, after all, just an example. Creating a site that looks more like Google is left as an exercise.
    my $links_per_page = 100; ### or any number ### get number of pages ### modulo is your friend my $num_pages = int (( scalar @link ) / $links_per_page); $num_pages++ if @link % $links_per_page; my $page = 0; my $counter = 0; my $file; my $other_pages; ### create per-page links for ( my $i = 1; $i <= $num_pages; $i++ ) { $other_pages .= "<a href='page_$i.html'>$i</a>\n"; } foreach ( @link ) { ### again, modulo is your friend here if ( ( $counter % $links_per_page ) == 0 ) { ### we create a new page here $page++; my $prev = $page - 1; my $next = $page + 1; $file = 'page_' . $page . '.html'; open Fh, "> $file" || die "Can't write to $file: $!\n"; ### header info and such print Fh "<html><head><title>Page $page"; print Fh "</title></head><body>\n"; print Fh "<h1>Page $page of links</h1>\n"; ### we only want a 'previous' link if there's ### a previous page if ( $page > 1 ) { print Fh "<br><a href='page_$prev.html'>"; print Fh "Previous</a>\n"; } print Fh $other_pages; ### we only want a 'next' link if there are ### more pages after this one if ( $page < $num_pages ) { print Fh "<a href='page_$next.html'>"; print Fh "Next</a>"; } print Fh "<br>\n"; } print Fh "$_\n"; ### print a link $counter++; } close Fh; ### The other files got closed when we opened ### new files using the same handle.
    HTH. HAND.