Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

syntax error near "){"

by greymoose (Beadle)
on Nov 06, 2007 at 11:07 UTC ( #649179=perlquestion: print w/ replies, xml ) Need Help??
greymoose has asked for the wisdom of the Perl Monks concerning the following question:

I have a piece of code that looks up two arrays from a table in a MySQL database and is then supposed to print out the information on a web page. (Sorry to those monks of greater learning but I haven't got beyond using PERL for cgi.) The data is looked up by exist_deadline.cgi which is called by about_deadline.cgi
The while loop (lines 30 -33 of about_deadline.cgi) where the information is supposed to print out always results in error messages:
syntax error at /usr/lib/cgi-bin/about_deadline.cgi line 30, near ") { +" syntax error at /usr/lib/cgi-bin/about_deadline.cgi line 33, near "}"

I've found another thread asking the same question and triple checked the answers that monk received. The error disappears if I take the call to the second script out. I can't find a missing semicolon or extra brace (yes, my editor does colour code my syntax). That's not to say that it isn't there somewhere but I am bamboozled. I'm posting the code below. Can anyone see what I've missed?

about_deadline.cgi
my ($conf) = new Config::General( -ConfigFile => 'somefile.conf', -ExtendedAccess => 1 ); my ($databaseUser)=$conf->value("user"); my ($databaseName) = $conf->value("name"); my ($databasePw) = $conf->value("pass"); # Declare local variables my ($dbh); my ($stmt, $sth); my (@deadlinetyp, @deadline); my $i = 0; <!--#exec cgi="/cgi-bin/exist_deadline.cgi" --> while ($deadlinetyp[$i]) { print $deadlinetyp[$i]." <b>".$deadline[$i]."</b><br>"; $i++; }
exist_deadline.cgi
print header; my ($conf) = new Config::General( -ConfigFile => 'somefile.conf', -ExtendedAccess => 1 ); my ($databaseUser)=$conf->value("user"); my ($databaseName) = $conf->value("name"); my ($databasePw) = $conf->value("pass"); # Declare local variables my $dbh; my ($stmt, $sth); my @aRow; my $j=0; $dbh = DBI->connect($databaseName, $databaseUser, $databasePw) || die "Connect failed: $DBI::errstr\n"; #Get available deadline details $stmt = "SELECT dead_typ, dead_line FROM deadlines"; #Prepare and execute the SQL query $sth = $dbh->prepare($stmt) || die "prepare: $stmt: $DBI::errstr"; $sth->execute() || die "execute: $stmt: $DBI::errstr"; while (@aRow = $sth->fetchrow()){ $deadlinetyp[$j] = @aRow[0]; $deadline[$j] = @aRow[1]; $j++; } # Clean up the record set and the database connection $sth->finish(); $dbh->disconnect();
Thanks in advance for your help.

Comment on syntax error near "){"
Select or Download Code
Re: syntax error near "){"
by syphilis (Canon) on Nov 06, 2007 at 11:19 UTC
    <!--#exec cgi="/cgi-bin/exist_deadline.cgi" -->

    I don't think that's valid perl code:
    use warnings; <!--#exec cgi="/cgi-bin/exist_deadline.cgi" --> while(1) { # line 5 print "."; last; } __END__ Outputs: syntax error at try.pl line 5, near ") {" syntax error at try.pl line 8, near "}" Execution of try.pl aborted due to compilation errors.
    Cheers,
    Rob
      Bang on Rob. It isn't valid PERL code. As soon as read the replies to my post I knew what I'd done. I put an HTML insert into a cgi script. Thanks for your input.
Re: syntax error near "){"
by KurtSchwind (Hermit) on Nov 06, 2007 at 13:03 UTC
    <!--#exec cgi="/cgi-bin/exist_deadline.cgi" -->
    Looks like you are either going for a comment, but used HTML comment notation rather than perl's comment notation. Or maybe you meant to use a require or a do to source the other perl file?
    --
    I used to drive a Heisenbergmobile, but everyone I looked at the speedometer, I got lost.
      Thanks for your input. I appreciate the considerate responses to a pretty obvious mistake.
Re: syntax error near "){"
by Errto (Vicar) on Nov 06, 2007 at 23:24 UTC

    It looks like you're trying to perform a server side include. This allows you to include the output of a CGI program in an otherwise static HTML page. But what you have here is not an HTML page but rather another CGI program. You can achieve this result, somewhat primitively, using the do function in Perl.

    That should be enough to get you started. But I'd suggest taking this CGI you're trying to include and turn it into a module whose functions you can call from your main script. Try Simple Module Tutorial for starters if you're not familiar with modules.

      Thanks Errto. This is the first time I've tried to use a separate script instead of a subroutine to avoid duplication. I've followed both of those links and I'll probably give the Module option a go.
      Cheers,
      Phil

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://649179]
Approved by andreas1234567
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-09-03 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls