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

Howdy all, I need some help with a script to admin a .dat file. It's for a guestbook I have so diligently been working on, and I need to be able to seperate the entrys into text boxes, have check boxes by them to delete them and whatnot. It's all dealing with flat files now, I'll do it in MySQL when I get a database. Can some one get me started somewhere? Thanks Dhoss

Replies are listed 'Best First'.
Re: Admin-ing a file?
by Improv (Pilgrim) on Apr 21, 2003 at 03:29 UTC
    I'm attempting to help based on the following assumptions:
    1. Your page is written as a CGI in Perl (just guessing by the fact that you're posting on PerlMonks
    2. Your flatfile is CSV or some other fairly simple format
    3. You're not asking how to design your database
    If any of the above are false, let us know, and we'll probably be able to help. In essense, what you should be doing to prepare for when MySQL is available is writing wrappers to encompass the common operations on your data. For your guestbook example, perhaps you'll want to create functions like:
    • register_user($fullname, $login, $privlvl)
    • add_new_comment($comment_target, $text, $login, $date)
    • replace_comment($entryid, $newtext)
    • get_login_from_fullname($fullname)
    • get_fullname_from_login($login)
    Initially, of course, implement them on your flatfile, but start writing (and testing) SQL versions that work with experimental versions of what the tables will be for your guestbook. When the database is available, ideally your SQL versions of the functions will be ready to go, and after you import the existing data into the database, there won't be any bumps. I hope this answers your question.
      Ooh, I guess they don't email you when you get a reply here. Sorry for the late reply; To answer some of the questions of Improv, you nailed all three of those. I am using a .dat file, like a csv file I am assuming, I'm not doing this version in mysql, and I am using p Yeerl no doubt. Ok, here is an example of my .dat file:
      <!--START:--> <table width=500 border=0 cellpadding=5 cellspacing=0><tr><td>Signed o +n:&nbsp;April 23, 2003</td></tr><tr><td>Name:Devin</td></tr><tr><td>E +mail:&nbsp; <a href='mailto:'puckchewer@cs.com>puckchewer@cs.com</a>< +/td></tr><tr><td>Country:USA</td><tr><td>State/Province/Territory:&nb +sp;Colorado</td></tr><tr><td>City:&nbsp;Loveland</td></tr><tr><td>Sit +e rating:&nbsp;10</td></tr><tr><td>Comments:<br>Testing my entry for +the second time to see if the buffer turned off.</tr><tr><td></table> <!--END:--><!--START:--> <table width=500 border=0 cellpadding=5 cellspacing=0><tr><td>Signed o +n:&nbsp;April 23, 2003</td></tr><tr><td>Name:Devin</td></tr><tr><td>E +mail:&nbsp; <a href='mailto:'puckchewer@cs.com>puckchewer@cs.com</a>< +/td></tr><tr><td>Country:USA</td><tr><td>State/Province/Territory:&nb +sp;Colorado</td></tr><tr><td>City:&nbsp;Loveland</td></tr><tr><td>Sit +e rating:&nbsp;10</td></tr><tr><td>Comments:<br>Testing my entry</tr> +<tr><td></table> <!--END:-->
      Yes, I am completely aware that I should generate my HTML on the fly but I haven't had time to re-write the script in order to do that. My main problems are figuring out what I need to do to manipulate the strings (I'm sure I'm just thinking too hard) in order to break them into their separate messages. If you could possible give me what you would normally do in a case like this, that would definitely help.
        Actually, there's a preference you can set in your profile that will at least make replies show up. Anyhow, yeah, this doesn't look like the easiest format to parse, because your data is all mixed into the HTML. The easiest way to deal with this, IMO, is to parse the whole thing into memory, and write it all back out if there are changes. Unfortunately, this is also slow, but at least the code will be clean. Here's code to do it:
Re: Admin-ing a file?
by TVSET (Chaplain) on Apr 21, 2003 at 03:26 UTC
    Can you provide a sample data from your .dat file? Meanwhile you can read the manual for split and documentation for CGI.pm module.

    Leonid Mamtchenkov

Re: Admin-ing a file?
by nite_man (Deacon) on Apr 21, 2003 at 08:23 UTC
    I think that you can use module File::Data which is an interface to file data.
          
    --------------------------------
    SV* sv_bless(SV* sv, HV* stash);