470,647 Members | 1,219 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

How to interpret $FORM{} variable ?

Hi,

While I'm studying a guestbook processing cgi perl script, I found
below segment commonly found in many illustrating examples of html
form processing.

# GET THE INPUT FROM THE CALLING HTML DOCUMENT
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}

I would like to know does $FORM is special or reserved variable in
perl just like $_[0], $ENV have special usage ?

:)
Jul 19 '05 #1
1 2371
lonelyplanet999 wrote:
While I'm studying a guestbook processing cgi perl script, I found
below segment commonly found in many illustrating examples of html
form processing.

# GET THE INPUT FROM THE CALLING HTML DOCUMENT
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}

I would like to know does $FORM is special or reserved variable in
perl just like $_[0], $ENV have special usage ?


You keep throwing out questions that you should be able to answer by
yourself. What happened when you tried to use some other variable name?

A couple of notes:

- The above code is old and not able to handle all kind of form data.
Use the standard module CGI.pm instead. Example:

use CGI;
my %FORM = new CGI->Vars;

Those two lines replace the above old code.

- In your question you mention $FORM, $_[0] and $ENV. The question
had made more sense if you had talked about the variables %FORM,
@_ and %ENV. For instance, %ENV is a reserved hash variable. To
access the CONTENT_LENGTH element in that hash, you can say
$ENV{CONTENT_LENGTH}.

Much to learn, right? Start now:

http://learn.perl.org/

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Justin Carter | last post: by
9 posts views Thread by franzkowiak | last post: by
13 posts views Thread by genetic.error | last post: by
3 posts views Thread by hermand | last post: by
2 posts views Thread by David W. Fenton | last post: by
4 posts views Thread by Greg Scharlemann | last post: by
1 post views Thread by Twayne | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.