Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

Using Forms and CGI

By Jennifer Kyrnin, About.com

5 of 6

How to Write the CGI

This line tells the CGI what language to run in, and the location.

#!/usr/local/bin/perl

These three lines call the three sub-routines in the script.

&parsedata;
&sendemail;
&printthanks;

This section takes the data from the input stream and converts it into name/value pairs that the CGI program can use.

sub parsedata
{
 read(STDIN, $in, $ENV{'CONTENT_LENGTH'});
 @in = split(/&/, $in);

 foreach $i (0 .. $#in)
 {
  $in[$i] =~ s/\+/ /g;
  $in[$i] =~ s/%(..)/pack("c",hex($1))/ge;
  ($key, $val) = split(/=/,$in[$i],2);
  $in{$key} .= '\0' if (defined($in{$key}));
  $in{$key} .= $val;
 }
}

5 of 6

Explore Web Design / HTML

More from About.com

Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. About.com Web Design A to Z
  5. Web Design Articles R-Z
  6. Web Design/HTML Articles U
  7. Using Forms and CGI

©2008 About.com, a part of The New York Times Company.

All rights reserved.