Re: Perl site - Elementary question



usenet@xxxxxxxxxxxxxxx said:
>kejoseph@xxxxxxxxxxx wrote:
>> I want to setup a "quick and dirty" site which grabs information from
>> users (in a form having 8-10 fields) and dumps it to a database.

>What you have probably created is a pure HTML form. The usual "Perl"
>approach would be to have a script that generates the form "on the fly"
>and that same script also processes the form. So you never write HTML.
>Instead of:
> <a href="www.google.com">Google</a>
>you write:
> a({href => 'www.google.com}, "Google")
>This is all done using the CGI.pm module, which will become your best
>friend.

There are places where a pure HTML form (not having any generated content)
is a good thing -- if you're going to have a form which is always
exactly the same for all clients, then there's no point in generating
that for each request. It makes much more sense to just write it in
HTML (or perhaps pre-generate it once from some kind of template and
then serve the generated form from a file.

Also, the above example doesn't do much magic -- the benefits of
HTML generation are largely in keeping the tags in balance. So, in
the above, the HTML generation will handle the "</a>" tag to be emitted
in the correct place, without needing to write one. Below is a more
complex example, which I think is better in highlighting the benefits
of generation (from CGI.pm docs):

print ul(
li({-type=>'disc'},['Sneezy','Doc','Sleepy','Happy'])
);

This example will result in HTML output that looks like this:

<ul>
<li type="disc">Sneezy</li>
<li type="disc">Doc</li>
<li type="disc">Sleepy</li>
<li type="disc">Happy</li>
</ul>

.... and in the above the "['Sneezy','Doc','Sleepy','Happy']" can be any
form of array reference (so, the data can be generated elsewhere in the
program, and reference to the array containing the data can be passed
to the routine generating the HTML).

HTML tables can be constructed similarly, as well as various form elements
(selection lists, button groups, ...). These go long way in always having
HTML in correct form, as the close tags (and a lot of other details) are
handled by the CGI module. One benefit of correct HTML is much less
"surprises" in how a page is rendered in different browsers.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
.