[prog] CGI programming

Almut Behrens almut-behrens at gmx.net
Tue May 20 14:45:08 EST 2003


Dan Richter wrote:
> 
> I'm trying to learn CGI programming. I've written and run some extremely 
> basic CGI scripts, but it's obvious that I'm going to need some outside 
> help to get much further. Can anyone suggest a good introduction to CGI 
> programming? Can anyone explain to me how CGI programming is usually done 
> in Perl (what helper functions/classes are used)?

it's a bit difficult to answer how CGI programming is "usually" done, as
there's a myriad of modules, techniques and paradigms to choose from. 
As so often, it depends on a variety of factors, whether a certain approach 
can be considered optimal for a specific purpose -- so, if you tell a bit 
more about what you're planning to do, ... :)

For the more simple cases, there's the module CGI (CGI.pm) or CGI::Lite
(I personally prefer the latter -- much less overhead...). With very simple 
requirements, you can even write the essential CGI interfacing code 
yourself (about 20 lines), which might make sense in certain environments.

For more complex tasks, there's a whole bunch of templating modules like
the Template Toolkit, Embperl, Mason, and about a dozen more. They all
try to make dynamic HTML generation easier, more modular, and better 
to maintain. (Those are from Perl's universe only -- there's also PHP, and 
lots of templating stuff for Java, etc., of course).

There's a quite good overview article (focusing on the world of Perl), which
I'd recommend reading before you make your choice for a particular module:

  http://www.perl.com/pub/a/2001/08/21/templating.html

In general, I personally prefer the Template Toolkit, at least in 
persistent contexts (i.e. where the Perl interpreter and all the modules 
_don't_ get reloaded on every HTTP request...). Also, I've had quite 
positive experiences with  Embperl.  Well, as already mentioned, 
it largely depends on the task at hand, and your personal preferences...

Most of the templating systems come with decent documentation, but 
if you should need further help to get started, don't hesitate to ask.

> 
> And here's a very specific question: I've noticed that Apache included the
> 
> following variable:
>     UNIQUE_ID=tPxaBwoAAFoAAHpvDoUAAAAD
> To state the obvious, it's some sort of unique ID. It seems to change
> every 
> time the script is invoked. How unique is it? Is it guaranteed to be
> unique 
> for this machine for, say, a decade?

The UNIQUE_ID variable is set by the Apache module "mod_unique_id",
the documentation of which contains quite a detailed description of the
rationale behind the specific implemention chosen...

  http://httpd.apache.org/docs/mod/mod_unique_id.html


Cheers,
Almut


-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!



More information about the Programming mailing list