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

Sirs and Madams, I've recently been more or less dumped into the world of perl. (Not that this is a bad thing.) My boss wants a savable and retrievable form. The form I made (http://www.nscl.msu.edu/~singleto/Workshop/detector-lab-wo.html). I even managed to set up an e-mail function. Sending those keyed values to a database and being able call them back at will based on a keyword or even a table of links remains a mystery. Unfortunately, I seem to get lost somewhere between print "Hello World!\n"; and Open (WORDSLIST, "wordslist"); in the grand old llama book. I've been scouring the web for existing code that someone might wish to share which would considerably lighten my load, but I've yet to find any. Can anyone point me in the right direction? Float me a clue? Help?

Replies are listed 'Best First'.
Re: Over my head
by Purdy (Hermit) on Nov 19, 2001 at 23:38 UTC
    Well, this is quite a broad question, but I'll take a stab at it.

    I would first read & research DBI, as it is pretty much the lingua franca of Perl & Database interactions.

    Design-wise, I'm a little out of sync with what's the latest & greatest way to do this, but I would recommend creating a subroutine to render the form and use a parameterized or global hash value to populate the various input fields. IE:

    sub render_form { %fields = shift; print <<"_HTML_"; Updated <input type="text" name="updated" value="$fields{updated}"> .... _HTML_ }

    May even want to investigate HTML::Template. Then you can create a new form/page where a lab worker can "login" with their previous work order ID (which DBI can generate for you) or click on a link to create a new work order.

    If they login with their previous work order, you query the database and populate the hash and pass that to your render_form function.

    Otherwise, you just pass them onto your render_form function and the fields will be blank for them to fill out.

    Then you need a new script (or handler within the current script) to take the fields (check out CGI) and either update the database (if they logged in) or insert a new record into the database.

    HTH,

    Jason

Re: Over my head
by Washizu (Scribe) on Nov 20, 2001 at 00:40 UTC

    Divide and conquer, take baby steps, whatever you want to call it, go after seemingly huge projects in small chunks. On Thursday, those of us in the US won't be trying to eat the whole turkey in one bite. We cut off a peice at a time and slowly pick away at it.

    What makes Perl so cool is that most of the chunks have already been taken care of for us in modules. Check out the following modules if you haven't already:

    • DBI
    • CGI

    If I were you, I'd first try getting a script to connect to a database. There are plenty of examples out there for you. Once I got that working, I'd try to select and print out some data. Then, I'd work on inserting/updating some data, etc.

    -----------------------------------
    Washizu
    The best offense is a good offense.

      That's good advice. If you're looking for example code, you can't do much better (IMHO) than Perl Cookbook by Tom Christiansen and Nathan Torkington, O'Reilly & Assocs.

      The pertinent chapters are 14, Database Access and 19, CGI Programming.

      HTH

      hagen
Re: Over my head
by ralphie (Friar) on Nov 20, 2001 at 04:12 UTC
    you might also want to take a look at the three database tutorials under tutorials here. a nice mix of basics and applied use.