Solved

Format Not Terminating

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now