[thelist] Quick and Dirty Environment Variables....

Keith cache at dowebs.com
Fri Jan 25 23:54:01 CST 2002


Anthony

Your tip (below) is excellent, if the programmer is familiar with using
OOP Perl modules. However most web scripts do not need OOP's
bloatware, running fine with straight Perl ("screaming code" as
Randal calls it). Don't misunderstand me, I think Perl modules are
great and use them a lot, when they are relevant, otherwise IMHO
their OOP structure hobbles Perl with the very archaic structures of
older languages that Perl famously escapes in it's original
procedural format.

Jesteruk published a great evolt article this week
http://evolt.org/article/Handy_Little_Perl_Script/17/19700/index.html
for parsing forms input (and cookies) when OOP is not called for
and when using an associative hash is irrelevant. I use a very
similar parsing sub routine to his and therefore also have a simple
subroutine that can be toggled on/off with a comment # during
development for displaying both the input and environment
variables. It references the @pairs array in jesteruk's article.

&get_vars;

sub get_vars{
print "Content-type: text/html\n\n";
for(@pairs){
  s/%(..)/chr(hex($1))/ge;
  tr/+/ /;
  print "<br><tt>$_</tt>\n";
}
for (sort keys %ENV) {
  print "<br><tt>$_=$ENV{$_}</tt>\n";
 }
exit;
}

Like Larry says, "Perl should work the way YOU think it should
work".

keith


> #! /usr/bin/perl
>
> use CGI;
> $query = new CGI;
> print $query->header;
> print $query->start_html(-title=>"Env Variables");
>
> print $query->h2('Form info') . "\n";
> print "<ul>\n";
> for $var (sort $query->param){
>  print $query->b($var) . ": " . $query->param($var) . "<br \>\n"; }
> print "</ul><br><br>\n";
>
> print $query->h2('Environment info') . "\n";
> print "<ul>\n";
> for $var (sort keys %ENV){
>  print $query->b($var) . ": " . $ENV{$var} . "<br \>\n";
> }
> print "</ul><br><br>\n";
> print $query->end_html();
>
> exit;




More information about the thelist mailing list