My suggestion is to parse this all once (perhaps with something like HTML::TokeParser) and place your records in a database. If you don't want to (or, for some reason, can't) run a full-on RDMBS, check out DBD::SQLite2 for a file-based RDBMS-in-a-Perl-module solution. For what you're doing, it should perform well enough.

Once you have these in a database, you can revise your guestbook code to (a)insert records instead of editing files, (b)generate HTML dynamically using something like HTML::Template, and (c)add your search function.

Your user table might look something like this:

ID UserName === ============ 1 Doug 2 JH

And your comments table would have a PostingUserID column that references the ID above. Your search, then, would look up the ID number of the user you want and then scan your comments table for posts by that ID. This is pretty standard DB stuff, so I apologize if I'm oversimplifying -- I don't know how familiar with DBs you are.

End result, you do a bit more work up-front, but you have code that's much more scalable both in terms of adding new features and handling more users. For example, migrating to a more robust DB like MySQL in the future (in order to deal with tens of thousands of users, perhaps) becomes relatively simple.

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

In reply to Re: Search function for guestbook history? by radiantmatrix
in thread Search function for guestbook history? by JCHallgren

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.