How to interpret $FORM{} variable ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lonelyplanet999

    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_L ENGTH'});

    # 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 ?

    :)
  • Gunnar Hjalmarsson

    #2
    Re: How to interpret $FORM{} variable ?

    lonelyplanet999 wrote:[color=blue]
    > 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_L ENGTH'});
    >
    > # 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 ?[/color]

    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_LE NGTH}.

    Much to learn, right? Start now:



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

    Comment

    Working...