
JennyW
journeyman
May 20, 2001, 2:20 PM
Post #16 of 123
(30741 views)
|
Re: Perl beginner - I need help please
[In reply to]
|
Can't Post
|
|
Hi mhx, You wrote… Yes, it is. You can change to this folder by typing cd "\program files" That worked great! Thanks! Thanks to your help I’m beginning to test .cgi scripts! However, I need your assistance, because I’m having some trouble. 1. Here’s my html Form… <HTML> <HEAD><TITLE>Most Basic CGI Input Page</TITLE></HEAD> <BODY> <FORM ACTION="emailtest.cgi" METHOD="POST"> <P>email, please: <INPUT TYPE="TEXT" WIDTH="25" NAME="Email_Address"> </P></FORM></BODY></HTML> 2. I tested my <html> Form with the following .cgi code. My results were strange. (The .cgi script below is suppose to accept any email address and display it on a new page). By the way, I haven’t used your code yet… #!c:\programme\perl\bin\perl.exe -w use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; use strict; I’m definitely going to use this code in the NEAR future. I just wanna get a handle on the basics first. Here’s the .cgi code I used… #!/usr/local/bin/perl # %FORM = &cgidecode(); $email = $FORM{Email_Address}; print "Content-type: text/html\n\n"; print "<HTML><HEAD><TITLE>Catching an email</TITLE></HEAD>\n"; print "<BODY><P>Address is: $email.</P></BODY></HTML>"; sub cgidecode { local(%vars, $val, $key, $last, $buffer, $pair, @pairs); # Checking the form method (GET or POST) used # in the HTML code. POST method sends data to # standard input, but GET adds it to the URL # and stores it in QUERY_STRING. if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } # Splitting up the data fields and store in array @pairs, # they are seperated with & @pairs = split(/&/, $buffer); # Splitting the variable names and the values and storing # them in the assoc. array %vars foreach $pair (@pairs) { ($key, $val) = split(/=/, $pair); $val =~ s/\+/ /g; $val =~ s/%(..)/pack("C",hex($1))/eg; if ($key eq $last) {$vars{$key} .= " ".$val; } else { $vars{$key} = $val; } $last = $key; } return(%vars); } After I entered an email address I was brought to a new screen, which displayed the following… #!c:/perl/bin/bin/perl # %FORM = &cgidecode(); $email = $FORM{Email_Address}; print "Content-type: text/html\n\n"; print "\n"; print " Address is: $email. "; sub cgidecode { local(%vars, $val, $key, $last, $buffer, $pair, @pairs); # Checking the form method (GET or POST) used # in the HTML code. POST method sends data to # standard input, but GET adds it to the URL # and stores it in QUERY_STRING. if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } # Splitting up the data fields and store in array @pairs, # they are seperated with & @pairs = split(/&/, $buffer); # Splitting the variable names and the values and storing # them in the assoc. array %vars foreach $pair (@pairs) { ($key, $val) = split(/=/, $pair); $val =~ s/\+/ /g; $val =~ s/%(..)/pack("C",hex($1))/eg; if ($key eq $last) {$vars{$key} .= " ".$val; } else { $vars{$key} = $val; } $last = $key; } return(%vars); } Do you know what could have happened here? Thanks, Jenny
|