Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > cryptic error in cgi script

Reply
Thread Tools

cryptic error in cgi script

 
 
andrey the giant
Guest
Posts: n/a
 
      10-13-2010
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 = '';
if ( $xdest =~ /a/ ) { $dest = ''; }
elsif ( $xdest =~ /u/ ) { $dest = ''; }
elsif ( $xdest =~ /c/ ) { $dest = ''; }
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 => '' } );
$ret = 1;
}
catch { $ret = 2; $err = "$_"; }
if ( ( $urgent =~ /yes/ ) && ( $ret != 2 ) )
{ #error here
$email = Email::MIME->create(
header => [
From => '',
To => $SMS,
],
body => "Urgent message in $dest.\n",
);
try {
sendmail( $email, { from => '' } );
$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();
}
 
Reply With Quote
 
 
 
 
andrey the giant
Guest
Posts: n/a
 
      10-13-2010
On Oct 12, 10:40*pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Sherm Pendley <sherm.pend...@gmail.com>:
>
> > andrey the giant <andrey....@gmail.com> writes:

>
> > > * * try {
> > > * * * * sendmail( $email, { from => 'postmas...@example.com' } );
> > > * * * * $ret = 1;
> > > * * }
> > > * * catch { $ret = 2; $err = "$_"; }

>
> > You're missing a semicolon after that catch block.

A subtle issue completely overlooked by one fluent in primarily C/C++/
Java.

>
> > The above is actually two anonymous sub references being passed to a
> > try() method via indirect object syntax (see 'perldoc perlobj') to mimic
> > the creation of new language syntax.

>
> 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.
>
> > But, code blocks don't normally
> > require semicolons after them, and your editor probably isn't aware
> > that this one does.

>


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

Everything works now.
Thanks to everybody.
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      10-13-2010
>>>>> "BM" == Ben Morrow <> writes:

>> Remember - only perl can parse Perl.


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

--
Uri Guttman ------ -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cryptic error none C++ 11 05-05-2010 10:43 PM
..and they say Windows error messages are cryptic! Cima NZ Computing 6 07-07-2009 08:54 AM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
"Load Report Failed." error... cryptic and evasive... Roy ASP .Net 1 05-05-2005 06:13 PM
Cryptic compiler/linker error messages with C++ templates Generic Usenet Account C++ 1 03-21-2005 08:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57