Okay, there are a couple ways to handle this. The database is a fine idea but probably overkill. The perl tradition is to do the minimum necessary to get the job done. So futzing with databases to handle a guestbook (unless its *insanely* huge) is antithetical to the nature of perl.

The other way to handle it is quick and dirty but cheap and easy to do which is chady's idea of a 'flatfile' - or just a text file that contains the comments.

Things to keep in mind. Unless you force it you cannot be assured that all of the comments are going to be on one line. It makes more sense to use a unique seperator between entries. From seperator to seperator counts as one entry. I ripped this out of another program of mine to show you how I did it.

sub read_quotes { open (QUOTES, "< $basedir$quotefile") || die "No quotes file!" +; while (<QUOTES>) { chomp; if (!($_ eq $seperator)) { $build .= "$_\n"; } else { push(@quotes,$build); $build = "-------\n"; #seperate body from sig } } close QUOTES; }
This builds an array of entries. Each entry will correspond to one guest book entry. Then, to print out a subset of them you use a very very simple for loop
for ($i = $min; $i <= $max; $i++) { print $quotes[$i]; }
$max and $min are the upper and lower bounds of the arrays section you want to print. For example, if you want to print 10 entries per pages the $min and $max for the 1st page would be 0 and 9. The 2nd page would be 10 and 19, 20 and 29 for the 3rd and so on. The max and min can be set with hidden values that are submitted when the user clicks on the 'next page' button.

One note about the design of this... The simplest thing in the world would be to run this all from the cgi-bin directory in one script. The template Chady talks about should just be part of your perl code. Do something like this;

script starts if no arguements print 1st page of guestbook exit else is arguement 'next page'? print page N build next page button with values for next page is argument 'previous page'? same as above but in reverse :) is argument 'add entry'? parse user entry and concatonate to end of guestbook file script ends
Make use of the CGI modules if you can to save time especially with parsing the user data. Enjoy.

In reply to Re: Max Submissions? by rapier1
in thread Max Submissions? by Anonymous Monk

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.