Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Format Not Terminating

Posted on 1997-02-28
1
Medium Priority
?
373 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 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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

722 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