in reply to Trying to write a CGI script for this piece of HTML
First of all always use strict mode and warnings in Perl. It means your scripts should start with
#!/usr/bin/perl -w use strict;
It forces you to declare all variables you are using with my. See also perldoc strict. It helps to catch a lot of errors in Perl code.
Second of all don't reinvent the wheel. Don't try to parse query params yourself - chances are that you doing it wrong. Reuse existing code. That is CGI.pm.
Instead of
$form_data = $ENV{'QUERY_STRING'}; $form_data =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C",hex ($1))/eg; # Replace the + char with space char. $form_data =~ s/\+/ /g; # Split $form_data into name/value pairs @fields = split (/&/, $form_data); # Init script variables with form data values # $form_name is the name from the form. # from the text fields... ($form_name, $candidate) = split (/=/, $fields[0]); ($form_name, $position) = split (/=/, $fields[1]); ($form_name, $education) = split (/=/, $fields[2]);
you should have something like
use CGI; my $q = new CGI; my $candidate = $q->param('candidate'); my $position = $q->param('position'); my $education = $q->param('education');
Let's move further
$form_name > dataform.html
You can't write data into file this way. Read perldoc perlopentut for info how you can open files and read from/write to them.
Probably you need something like:
open(OUT, "> dataform.html") or die "Can't open file: $!"; print "Candidate: $candidate\n"; print "Position: $position\n"; print "Education: $Education\n\n"; close OUT;
This writes submited data into dataform.html. Probably you need to adjust format.
Well, I hope I gave enough info to do some homework (i.e. reading docs).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Trying to write a CGI script for this piece of HTML
by villa (Initiate) on Nov 28, 2001 at 22:12 UTC | |
by IlyaM (Parson) on Nov 28, 2001 at 22:31 UTC |