cryptic error in cgi script

A

andrey the giant

Vim doesn't give me any red marks and the code looks right, but I get
the following errors:
syntax error at contact.pl line 50, near ")
{"
syntax error at contact.pl line 64, near "}"
contact.pl had compilation errors.

The code is a cgi email script. All sensitive data has been
genericized.

The code is:
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use Email::MIME::Creator;
use Email::Sender::Simple qw(sendmail);
use Try::Tiny;

our $cgi = CGI->new;
our $name = $cgi->param('name');
our $addr = $cgi->param('email');
our $subject = $cgi->param('subj');
our $xdest = $cgi->param('dest');
our $message = $cgi->param('body');
our $urgent = $cgi->param('urgent');
if ( !defined($subject) || !length($subject) ) { $subject = ""; }
if ( !defined($urgent) || !length($urgent) ) { $urgent = "no"; }
my $defineds = 0;
$defineds |= 1 if ( defined($name) && length($name) );
$defineds |= 2 if ( defined($addr) && length($addr) );
$defineds |= 4
if ( defined($xdest) && length($xdest) && ( $xdest =~ /[aucm]/ ) );
$defineds |= 8 if ( defined($message) && length($message) );

our $complete = ( $defineds == 15 );
our $ret = 0;
our $err = "";
if ($complete) {
our $dest;
our $SMS = '(e-mail address removed)';
if ( $xdest =~ /a/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /u/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /c/ ) { $dest = '(e-mail address removed)'; }
elsif ( $xdest =~ /m/ ) { $dest = '@example.com'; }
our $email = Email::MIME->create(
header => [
From => $name . ' <' . $addr . '>',
To => $dest,
Subject => $subject,
'X-Source' => 'webform',
],
body => $message,
);
try {
sendmail( $email, { from => '(e-mail address removed)' } );
$ret = 1;
}
catch { $ret = 2; $err = "$_"; }
if ( ( $urgent =~ /yes/ ) && ( $ret != 2 ) )
{ #error here
$email = Email::MIME->create(
header => [
From => '(e-mail address removed)',
To => $SMS,
],
body => "Urgent message in $dest.\n",
);
try {
sendmail( $email, { from => '(e-mail address removed)' } );
$ret = 3;
}
catch { $ret = 4; $err = "$_"; };
}
} #and here
print $cgi->header();
if ( $ret == 0 ) {
print $cgi->start_html('Message not sent'),
"Not all required fields were filled", $cgi->end_html();
}
elsif ( $ret == 1 ) {
print $cgi->start_html('Message sent'), "Message successfully
sent",
$cgi->end_html();
}
elsif ( $ret == 2 ) {
print $cgi->start_html('Error sending mail'), "Sendmail: $err",
$cgi->end_html();
}
elsif ( $ret == 3 ) {
print $cgi->start_html('Message sent'),
"Message successfully sent, mobile notifed", $cgi->end_html();
}
elsif ( $ret == 4 ) {
print $cgi->start_html('Error sending mail'),
"Message successfully sent, but mobile could not be notified:
$err",
$cgi->end_html();
}
 
A

andrey the giant

A subtle issue completely overlooked by one fluent in primarily C/C++/
Java.
No it's not. It parses as (and could in fact be written as)

    try( sub { ... }, catch( sub { ... } ) )

where 'catch' is a subroutine that packages up the subref so 'try' knows
what it is.

Ugh, I'm so used to C/C++/Java I totally missed the semicolon after
the catch in the cpan docs for Email::Sender::Simple :|
And I thought C++ templates gave cryptic error messages :p

Everything works now.
Thanks to everybody.
 
U

Uri Guttman

BM> PPI?

it fails with wacky prototypes and such as it doesn't do a true parse
based on declarations. it is a very good top level parser though.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top