in reply to Using Perl to make Html file

This question seems closely related to the one posted by PaulShotgun under the title Help with updating HTML from drop down menu's please!. And from what I can tell, mostly the same answers were given; read the POD for CGI.pm, read Learning Perl, and ask specific questions. You wouldn't happen to be that same person would you? ;)

I understand that it can be intimidating coming to grips with what it takes to bring the worlds of Plain Text, Perl, CGI, and HTML together. Each is its own entity, and requires a new and different skillset.

Let me try to suggest how you might approach your problem.

First, understand that Perl can be used to read input in the form of text files, HTML, or any of a nearly unlimited number of formats and types of input. However, Perl doesn't inherently know anything about HTML. Perl doesn't even inherently know how to make text pretty with things like bold and italics. All this is stuff you have to know how to do before you can tell Perl how to do it for you.

Now for program structure.

By reading your two posts, I get the impression that you would like to have a webpage that has a list of items that family members have requested for Christmas. You also wish to allow other members to select items from that list and check them off as being purchased by mom, dad, or whoever. In your first post you discussed drop-down menus. Let me just make a few suggestions:

Start with a flat-file that is newline delimited for each record, and :: (double colon) delimited for each field within a record. Each line could contain a gift idea, and its intended recipient (separated by a double colon). After someone has assumed responsibility for buying that item, the purchaser's name will also be included as a third field on the line, again double-colon delimited.

The first thing the Perl script should do is figure out whether it's being invoked via "submit" button or not. If not, it should read in the datafile, and then generate a webpage showing each gift-idea, the gift's intended recipient, and the person who has assumed responsibility for buying the gift. Any gift/recipient pair that doesn't yet have a purchaser, would perhaps have a drop-down list of possible purchasers next to it. At the bottom of the form, there'll be a submit button.

On the other hand, if the Perl script is invoked as an HTML Form Action (someone clicked the submit button), the script must ensure that whatever user input came through is valid, and, if so, should update the datafile to add the name of the purchaser next to whatever items that purchaser just accepted responsibility for. The script should then continue by reading in the data file and outputting the same HTML form as described in the previous paragraph.

That's, as I understand it, the basic premise of your needs. The script is to be executed as a CGI script. It will take input from the datafile, from the web form, and will create new output to the datafile and the browser based on the input.

This is exactly the job for CGI.pm. You may also find it handy to either use a tied file or a storable datastructure for your data file needs. A single-family-oriented script doesn't need to worry about scalability, so a database may not be necessary, though it certanly wouldn't hurt anything to use a simple database such as AnyData. You will want to be careful about file locking. You will also want to be careful not to allow tainted data into your datafile. Remember that just because you have control over your form, you don't have control over other people who might write their own script to feed their own data to your script, bypassing your form altogether. That's probably unlikely for a simple single-family-oriented script. But it's possible.

You will also want to exercise caution in parsing the HTML form input. That is why CGI.pm is such a good idea. It does the dirty work for you.

One observation. If you are struggling with how to output bold and italic words in HTML via a Perl script, the rest of the project may be a little beyond your current skill level. If you dive into the books now you'll probably be able to get it done. But if you don't dig into the books and POD's mentioned by others in this thread and your other thread right now, the project won't be done before Christmas. This isn't terribly intricate stuff, but it does require some investment in time and effort to learn.

By the way, bold is expressed with a <b></b> tag set in HTML, and can be output via Perl as simply as 'print "<b>Some text</b>\n";'


Dave


"If I had my life to live over again, I'd be a plumber." -- Albert Einstein