Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Format Not Terminating

Posted on 1997-02-28
1
Medium Priority
?
377 Views
Last Modified: 2013-12-25
I am desperately trying to get any CGI mail form to work.  I am using this
script from the book, CGI Programming with Perl:

#!/user/local/bin/perl

# Perl program to send mail to a user.

$mailprog = '/usr/lib/sendmail';

print "Content-type: text/html\n\n";

if ($ENV{'REQUEST_METHOD'} eq "get") { $buffer = $ENV{'QUERY_STRING'}; }
else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }

@nvpairs = split(/&/, $buffer);
foreach $pair (@nvpairs)
{
    ($name, $value) = split(/=/, $pair);

    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    $FORM{$name} = $value;
}

$recipient = $FORM{'receiver'};

#
# format the mail file
format MAIL =
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$value
.

# Open the mail file and write to it
open (MAIL, "|$mailprog $recipient") || die "$mailprog not available.\n";
print MAIL "From: $FORM{'sender'}\n";
print MAIL "Subject: Form test from $FORM{'sender'}\n\n";

print MAIL "Dear $FORM{receiver},\n\n";
print MAIL "\n";
print MAIL "The user chose:\n\n";
foreach $pair (@nvpairs)
   {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    print MAIL "$name = $value\n";
   }
print MAIL "\n";
close (MAIL);

print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Mail Sent</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<P>Mail has been sent from $FORM{'sender'} to $FORM{'receiver'}.\n";
print "</BODY>\n";
print "</HTML>\n";

The error message I get when executing it is:

"Format not terminated in file at line 58 (the last line), next char ^ ?"

I hope somebody out there can help me, for I have stacks of books that
don't answer this.

Thanks for your time,

Alyssa
0
Comment
Question by:cosmic
1 Comment
 
LVL 1

Accepted Solution

by:
evilgreg earned 200 total points
ID: 1827482
Here's the problem:

# format the mail file format MAIL =
~~
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$value
.


Perl is complaining because it did not find the period above. Make sure that the period is flush all the way to the left (i.e. it is the first character on the line). To make it clean, erase that line and retype it, putting a period, then hitting return to get the next line. The single period tells the format where to end - if perl does not detect it, it thinks that all the code after it is part of the format, and generates the error you received, which is perl's way of saying -"Hey! I got to the end of the code, but you never ended your format!!" :)

 
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question