Don't understand why I'm getting a "Can't modify not in scalar assignment
at line 3, near "}:", when I run my cgi compiler & the script obviously
doesn't run in the browser.
I'm new to Perl and am attempting a script that I found in a book. You
would think that it would run without modification! :(
PLEASE HELP!!!
Craig
!#C:\Perl\Bin\Perl.exe
$content_length=$ENV{'CONTENT_LENGTH'};
read (STDIN, $posted_information, $content_length);
$posted_information=~ s/%([\dA-Fa-f][dA-Fa-f])/pack ("C", hex ($1))/eg;
$posted_information=~ s/\+/ /g;
@fields=split(/&/, $form_data);
($label, $user_name) = split(/=/, $field[0]);
($label, $email_address) = split(/=/, $field[1]);
($label, $tel_number) = split(/=/, $field[2]);
($label, $fav_color) = split(/=/, $field[3]);
($bicycles, $cereal, $pomo)=(0,0,0);
#"calculate" interests
foreach $value (@fields) {
if ($value=~ /bicycles/) {
$bicycles=1;
}
elsif ($value=~ /cereal/) {
$cereal=1;
}
elsif ($value=~ /pomo/) {
$pomo=1;
}
}
#check email for "@"
@check_email = split(//, $email_address);
foreach $letter (@check_mail) {
if ($letter eq "@") {
$good_email=1;
last;
}
}
#count number of digits (i.e. \d)
@check_tel_number = split(//, $tel_number);
foreach $number (@check_tel_number) {
if ($number =~ /\d/) {
$digits++;
}
}
if ($digits == 10) {
$good_tel_number = 1;
}
#start of OUTPUT - send HTML headers
print "Content-type: text/html", "\n\n";
print "<html>\n<head>\n";
######################################################################################
#if email and tel phone numbers aren't valid, have user re-enter
if (!$good_email | !$good_tel_number) {
print "<title>Invalid Data</title>\n<body>\n";
print "<h2>Invalid Data</h2>\n";
print "<p>You have entered invalid data in the form. Please correct \n";
print "the data in the fields with red labels.</p>\n";
print "<form action=\"dosurvey.cgi\" method=post\n";
print "<table border=0>\n<tr>\n<td align=right>User name:</td>\n";
print "<td><input type=\"text\" size=40 maxsize=60 name=\"user_name\"
value=\"$user_name\"></td>\n</tr>\n";
print "<tr>\n";
#bad email
if (!$good_email) {
print "<td align=right><font color=#ff0000><b>Email Address:</b></font>
</td>\n";
}
#good email
else {
print "<td align=right>Email Address:</td>\n";
}
#parse contents of previously-entered data in Email field
print "<input type=\"text\" size=40 maxsize=60 name=\"email_address\"
value=\"$email_address\"></td>\n</tr>\n";
#bad phone number
if (!$good_tel_number) {
print "<td align=right><font color=#ff0000><b>Telephone
Number:</b></font>
</td>\n";
}
#good phone number
else {
print "<td align=right>Telephone Number:</td>\n";
}
#parse contents of previously-entered data in Telephone Numpber
print "<input type=\"text\" size=13 maxsize=13 name=\"tel_number\"
value=\"$tel_number\"></td>\n</tr>\n";
#parse previously-selected favorite color choices
print "<tr>\n<td align=right>Favorite Color:</td>\n";
print "<td><select name=\"fav_color\">\n";
#red selected
if ($fav_color eq "red") {
print "<option value=\"red\" SELECTED>Red\n<option value=\"blue\">
Blue\n<option value=\"green\">Green\n</selected>\n";
}
#blue selected
elsif ($fav_color eq "blue") {
print "<option value=\"red\">Red\n<option value=\"blue\" SELECTED>
Blue\n<option value=\"green\">Green\n</selected>\n";
}
#green selected
elsif ($fav_color eq "green") {
print "<option value=\"red\">Red\n<option value=\"blue\">
Blue\n<option value=\"green\" SELECTED>Green\n</selected>\n";
}
#parse interests
print "<tr>\n<td align=\"right\">Interests:</td>\n";
#bicycles checked?
print "<td><input type=\"checkbox\" name=\"bicycles\" value=\"yes\" ";
if ($bicycles==1) {
print "CHECKED";
}
print ">Bicycles<br>\n";
#cereal checked?
print "<input type=\"checkbox\" name=\"cereal\" value=\"yes\" ";
if ($cereal==1) {
print "CHECKED";
}
print ">Breakfast Cereal<br>\n";
#Postmodern Architechture checked?
print "<input type=\"checkbox\" name=\"pomo\" value=\"yes\" ";
if ($pomo==1) {
print "CHECKED";
}
print ">Postmodern Architechture</td>\n</tr>\n";
#submit button
print "<tr>\n<td><br></td>\n<td><input type=\"SUBMIT\" value=\"Submit
Survey\">
</td>\n</tr>\n";
print "</table>\n</form>\n";
}
######################################################################################
#OR print THANK YOU response
else {
print "<title>Thank You</title>\n<body>\n";
print "<p>Thanks for filling out the form!</p>\n";
#output info to a file
open (OUTPUT, ">> surveyrecord.txt");
print OUTPUT $user_name, ":", $email_address, ":", $tel_number, ":",
$fav_color, ":", $bicycles, $cereal, $pomo, "\n";
close (OUTPUT);
}
print "</body>\n</html>";
---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
[EMAIL PROTECTED]
For non-automated Mailing List support, send email to
[EMAIL PROTECTED]