Solved

Format Not Terminating

Posted on 1997-02-28
1
364 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 100 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

778 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