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

I have the following lines in my code:
print $q->header("text/html\n\n"), $q->start_html(-title=>"Data Report"), "This is the report for~~<br>";
When I run the program, I keep getting "syntax error near 'print'". I have used the same format in other codes but this is the only one that gives this error. How can I solve this?


Update: I appreciate the sugggestions, however the problem still remains. The line above print defines a variable and ends with a semicolon. I changed $q so that it is now my $q = CGI->new; Is there something wrong with my format?


Update2: Here is the exact error-> "Syntax error at /home/www/code.cgi line 92 near "print", referer: http://localhost/reports.html"
This is the code around print:
my $last_time = 0; print $q->header("text/html\n\n"), #This is line 92 $q->start_html(-title=>"Data Report"), "This is the report for~~<br>";
I'm baffled. This is the only code I'm having trouble with.

Replies are listed 'Best First'.
Re: Syntax error near Print
by ccn (Vicar) on Nov 21, 2008 at 20:47 UTC
    Check if semicolon present at the end of line above the "print"
Re: Syntax error near Print
by ikegami (Patriarch) on Nov 21, 2008 at 20:52 UTC
    That means Perl is seeing print, but it's expecting something else. The error is actually earlier. Check what's missing(?) before the print.
Re: Syntax error near Print
by TimToady (Parson) on Nov 21, 2008 at 22:13 UTC
    If that's the actual error message, it doesn't look like a Perl error message to me. Perhaps the code isn't getting anywhere near the perl interpreter in the first place? Check your server configuration...

      If that's the real error message, then my error identification tools say that it is either an SQL or C error. So I'm betting it is a paraphrase of the error message (removing the line number and filename information).

      But I don't really have anything useful to offer beyond the many other replies. I just found the idea of CGI Perl code getting fed to a database or C compiler amusing. :)

      - tye        

Re: Syntax error near Print
by graff (Chancellor) on Nov 22, 2008 at 18:58 UTC
    When I run the program, I keep getting "syntax error near 'print'".

    Perl error messages generally report the line number in your script where the error occurred. (If you didn't see a line number in the error message, this would be evidence in favor of what others concluded -- maybe this isn't an error message from perl.)

    Did you confirm that the line number in the error message matches the line number that you've shown us?

    For future reference, when posting a question like this, it is best to paste in the exact text of the error message, and to show not only that particular line of your code, but also at least a few lines around it.

    When variables or objects are used in the line causing the error, it also helps to say a little bit (or show additional code) to clarify what values (if any) have been assigned to the variables.

Re: Syntax error near Print
by jeffa (Bishop) on Nov 21, 2008 at 20:46 UTC

    This code works for me when I add this before your code:

    use CGI; my $q = CGI->new;

    Sometimes you have to explicitly use parens with print, but your code seems fine to me. :/

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Syntax error near Print
by Anonymous Monk on Nov 21, 2008 at 20:45 UTC
    Examine things near print
Re: Syntax error near Print
by mikelieman (Friar) on Nov 21, 2008 at 20:44 UTC
    What's $q ? Do you have more code which demonstrates the issue?
      Looks like a CGI object.