Solved

Format Not Terminating

Posted on 1997-02-28
1
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
This article will show, step by step, how to integrate R code into a R Sweave document
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

751 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