gvs_jagan has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, i have made the corrections as suggested in the previous threads. However, iam still encountering the following error

Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
. Execution of jsdisp.cgi aborted due to compilation errors.

I have numbered the left curly brackets in the code with (#1...#12) and the right curly brackets with (#1'...#12').
I request once again for the wisdom of the monks.

thanking in advance , jagan

. code as follows

#!/usr/bin/perl use DBI ; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowsers fatalsToBrowser); my($username) = "someuser"; my($password) = "knownuser"; my($dbh) = DBI->connect ("DBI:mysql:hf", $username , $passwor +d); my($empName) = param("empName"); my($year) = param("year"); my($mon) = param("mon"); my($count) = 0; my($sth , @arr); DBI -> trace(4 , 'dbitrace'); if($year && $mon) { # 1 my($empName) = param("empName"); my($year) = param("year"); my($mon) = param("mon"); if($empName) { #2 my($sth) = $dbh->prepare("select * from jobStat wh +ere cdate> '$year$mon00' AND cdate<'$year($mon++)00' AND empName='$em +pNAme'"); $sth->execute(); @arr = $sth->fetchrow_array() if(defined@arr) { #3 while(@arr=$sth->fetchrow_array()) { #4 $count++; } #4' print <<end_of_html; Content-type: text/html <html><head><title> Job Status Display Page </ +title></head> <body> <readmore> <TABLE BORDER=1 HEIGHT=8%><TR> <TD WIDTH=10% ALIGN='middle' VALIGN='center'>C +urrent Date</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='center'>N +ame</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='center'>J +ob Allocated</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='center'>A +llocation Date</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='center'>T +arget Date</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='center'>J +ob Under Execution</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='center'>J +ob Pending </TD> <TD WIDTH=15% ALIGN='middle' VALIGN='center'>R +emark </TD> </TR></table></readmore></body></html> end_of_html while(@arr=$sth->fetchrow_array()) { #5 print <<end_of_html; Content-type: text/html <html><head></head> <body><readmore> <TABLE BORDER=0 HEIGHT=8%><TR> <TD WIDTH=10% ALIGN='middle' VALIGN='c +enter'>$arr[5]</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='c +enter'>$arr[8]</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='c +enter'>$arr[1]</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='c +enter'>$arr[6]</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='c +enter'>$arr[7]</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='c +enter'>$arr[2]</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='c +enter'>$arr[3]</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='c +enter'>$arr[4]</TD> </TR> </table> </readmore></body> </ht +ml> end_of_html } # 5' end of while(@arr=$sth->fetchrow_arra +y()) } # 3' end of if(defined@arr) else { #6 print <<end_of_html; Content-type: text/html <html><head><title> Job Status Display Page</t +itle></head> <body> No Record found for $empName for the given dat +es.<p> <a href="/jsdisp.html" > Back </a> </body></html> end_of_html } #6' end of else for if(defined@arr) } #2' if $empName has a value else #7 if empName is null , process the query for year and m +onth { my($sth) = $dbh->prepare("select * from jobStat where + cdate> '$year$mon00' AND cdate<'$year($mon++)00'"); $sth->execute(); @arr = $sth->fetchrow_array() if(defined@arr) { #8 while(@arr=$sth->fetchrow_array()) { #9 $count++; } #9' print <<end_of_html; Content-type: text/html <html><head><title> Job Status Display Page </ +title></head> <body><readmore> <TABLE BORDER=1 HEIGHT=8%><TR> <TD WIDTH=10% ALIGN='middle' VALIGN='center'>C +urrent Date</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='center'>N +ame</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='center'>J +ob Allocated</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='center'>A +llocation Date</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='center'>T +arget Date</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='center'>J +ob Under Execution</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='center'>J +ob Pending </TD> <TD WIDTH=15% ALIGN='middle' VALIGN='center'>R +emark </TD> </TR> </table> </body></readmore></html> end_of_html while(@arr=$sth->fetchrow_array()) { #10 # 1) id 2) ja 3) je 4)jp 5) remark 6) +cdate 7) adate 8) tdate 9) empName print <<end_of_html; Content-type: text/html <html><head></head> <body> <readmore> <TABLE BORDER=0 HEIGHT=8%><TR> <TD WIDTH=10% ALIGN='middle' VALIGN='c +enter'>$arr[5]</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='c +enter'>$arr[8]</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='c +enter'>$arr[1]</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='c +enter'>$arr[6]</TD> <TD WIDTH=10% ALIGN='middle' VALIGN='c +enter'>$arr[7]</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='c +enter'>$arr[2]</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='c +enter'>$arr[3]</TD> <TD WIDTH=15% ALIGN='middle' VALIGN='c +enter'>$arr[4]</TD> </TR> </table></readmore> </body> </ht +ml> end_of_html } #10' end of while(@arr=$sth->fetchrow_ar +ray()) } # 8' end of if(defined@arr) else #else for 2nd if(defined(@arr)) { #11 print <<end_of_html; Content-type: text/html <html><head><title> Job Status Display + Page</title></head> <body> No Record found for the given dates.<p +> <a href="/jsdisp.html" > Back </a> </body></html> end_of_html } # 11' end of else for if(defined@arr) } #7' end of else for if($empName) } #1' end of if($year && $mon) else #if month or year is not given { #12 print <<end_of_html; Content-type: text/html <html><head><title> Job Status Display Page</title></head> <bo +dy> Select year and month. <p> <a href="/jsdisp.html" > Back </a> </body></html> end_of_html } #12'

READMORE tags added by Arunbear

  • Comment on Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
  • Download Code

Replies are listed 'Best First'.
Re: Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
by davido (Cardinal) on Aug 16, 2005 at 07:39 UTC

    Are you sure that the code you posted gives the error you've described? When I run it I get a message about the failure to export a function called "warningsToBrowsers", and compilation aborts. That's because the function is called "warningsToBrowser" (not Browsers).

    When I fix that typo, I get some other compiletime errors such as:

    Software error: syntax error at mytest.pl line 31, near "){" syntax error at mytest.pl line 89, near "}" mytest.pl had compilation errors.

    The first error is because you're missing a semicolon ";" at the end of line 29.

    The second error also goes away when you fix line 29, but then you'll get a message related to the fact that you're also missing a semicolon at the end of line 96. Fix that one and your script will at least compile.

    Semicolons at the end of statements are as important as closing quotes and curly brackets. If one is missing, Perl doesn't know where one sentence ends and the next begins. This throws the compiler off, and you'll get error messages that misreport the errant line number, because the problem isn't detected at the point where you forgot the semicolon, it's detected at the point where Perl realizes you've forgotton something. ...that can be a few lines after the mistake.

    Updated: By the way, you probably don't need to be testing for definedness of @arr. It usually is correct to test whether @arr has elements: "if( @arr ) { ....". The documentation for defined explains:

    Use of defined on aggregates (hashes and arrays) is deprecated. It used to report whether memory for that aggregate has ever been allocated. This behavior may disappear in future versions of Perl. You should instead use a simple test for size:

    if (@an_array) { print "has array elements\n" } if (%a_hash) { print "has hash members\n" }

    Update2: One last little piece of advice that I'm not sure has been made clear yet: When Perl gives you an error message, if when you look on the line Perl reports as being in error you don't see anything wrong, scan back (or up) in the script a few lines. It's often the result of something you did wrong in a previous line.


    Dave

Re: Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
by sk (Curate) on Aug 16, 2005 at 07:37 UTC
    You are missing semicolons -

    C:\>perl -c curly syntax error at curly line 31, near ") {" syntax error at curly line 89, near "}" curly had compilation errors.
    I checked a few lines above and i don't see semicolons.

    Note: line 89 error is not quite accurate as the compiler is not reading the lines correctly due the missing semicolon. Once you fix that first error and rerun perl -c you will see an error message around the line # where semicolon was missing. It will not give the exact line number but it should be close enough

    -SK

    Update: forgot to mention that i actually commented out your use CGI::Carp for the perl -c output i showed you (see davido's post below why there is an error in that line).

Re: Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
by davorg (Chancellor) on Aug 16, 2005 at 10:31 UTC

    This isn't a personal debugging service you know. Please try asking Perl to tell you what the problems are with your code. That will save us all a lot of time.

    perl -c your_code.pl

    Running that, I found three errors in your code. One export from CGI.pm which is misnamed and two lines where you are missing the final semicolon. Fixing those enabled your program to compile cleanly. Of course, I can't run it as I don't have your database.

    Update: I see that you've already asked exactly the same question three hours ago? Why waste everyone's time by posting it again? Particularly as the comments on your previous post explain exactly what your problems are.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

    Reparented from duplicate thread 484115 by Arunbear

Re: Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
by lidden (Curate) on Aug 16, 2005 at 07:47 UTC
    You have included the CGI module use its features. No need to make your own "content-type ..." and stuff that it gives you.

    perl -M'CGI":standard"' -wle 'print header, start_html("Foo"), " blah bla", end_html'

Re: Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
by Anonymous Monk on Aug 16, 2005 at 07:32 UTC

    Hello ,

    i think the problem in line 29 and 96

    it should be as follow

     @arr = $sth->fetchrow_array();

    bye

Re: Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
by poj (Abbot) on Aug 16, 2005 at 21:42 UTC
    Hi, You may find it easier to locate errors in your code if it were restructured to clarify and simplify the logic and eliminate many brackets. Here is an example, it may not do exactly what you want but I hope this gives you the idea.
    #!/usr/bin/perl use DBI ; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my($username)= "someuser"; my($password)= "knownuser"; my($dbh)= DBI->connect ("DBI:mysql:hf", $username , $password); my($empName)= param("empName"); my($year) = param("year"); my($mon) = param("mon"); DBI -> trace(4 , 'dbitrace'); # logic my $result; if ($year && $mon){ $result = getResult($empName); } else{ $result = "Select year and month. <br>"; } # result print <<end_of_html; Content-type: text/html <html><head><title> Job Status Display Page</title></head> <body> $result <a href="/jsdisp.html" > Back </a> </body></html> end_of_html #process sub getResult { my $empName = shift; my $table = q!<table border="1" height="8%"> <tr valign="center" align="middle"> <td width="10%">Current Date</td> <td width="10%">Name</td> <td width="15%">Job Allocated</td> <td width="10%">Allocation Date</td> <td width="10%">Target Date</td> <td width="15%">Job Under Execution</td> <td width="15%">Job Pending </td> <td width="15%">Remark </td> </tr>!; my $date1 = $year.$mon.'00'; my $date2 = $year.($mon++).'00'; my $sql = "select * from jobStat where cdate > ? and cdate < ?"; my $noMsg = "No records found for given date.<br>"; if ($empName){ $sql .= " and empName='$empName'"; $noMsg = "No records found for $empName for given date.<br>"; } my $sth = $dbh->prepare($sql); $sth->execute($date1,$date2); my $count=0; while (my @arr = $sth->fetchrow_array){ $table .= qq!<tr valign="center" align="middle"> <td>$arr[5]</td> <td>$arr[8]</td> <td>$arr[1]</td> <td>$arr[6]</td> <td>$arr[7]</td> <td>$arr[2]</td> <td>$arr[3]</td> <td>$arr[4]</td> <tr>!; ++$count; } if ($count==0){ return $noMsg; } else { $table .= q!</table>!; return $table; } }
    poj
Re: Missing right curly or square bracket at jsdisp.cgi line 178, at end of line syntax error at jsdisp.cgi line 178, at EOF
by derby (Abbot) on Aug 16, 2005 at 19:21 UTC

    ++ to sk and davido. Also, if you use 'use strict' you'll see that your sql is going to fail miserably (hint - what's $mon00 - probably not what you think).

    -derby