Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl syntax check

Reply
Thread Tools

perl syntax check

 
 
Helmut Richter
Guest
Posts: n/a
 
      01-20-2012
I'd like to do a perl syntax check as distinct from an execution. I am
well aware that there are many errors that cannot be found without
execution but I'd like to first remove the errors that can be found
without execution and *then* execute the script. My attempt was using the
-wc flag, but this has no effect whatsoever.

> perl -wc ali.pl

[Fri Jan 20 16:51:56 2012] ali.pl: Variable "$body" is not imported at
ali.pl line 362.
[Fri Jan 20 16:51:56 2012] ali.pl: (Did you mean &body instead?)
[Fri Jan 20 16:51:56 2012] ali.pl: Variable "$body" is not imported at
ali.pl line 363.
[Fri Jan 20 16:51:56 2012] ali.pl: (Did you mean &body instead?)
[Fri Jan 20 16:51:56 2012] ali.pl: Variable "$body" is not imported at
ali.pl line 365.
[Fri Jan 20 16:51:56 2012] ali.pl: (Did you mean &body instead?)
[Fri Jan 20 16:51:56 2012] ali.pl: Variable "$body" is not imported at
ali.pl line 419.
[Fri Jan 20 16:51:56 2012] ali.pl: (Did you mean &body instead?)
[Fri Jan 20 16:51:56 2012] ali.pl: Variable "$body" is not imported at
ali.pl line 432.
[Fri Jan 20 16:51:56 2012] ali.pl: (Did you mean &body instead?)
Status: 500
Content-type: text/html

<h1>Software error:</h1>
. . .


The script is intended as CGI Script. The format of the error messages, to
wit the same format as web server log entries and a status code 500, is
hardly conceivable as pure syntax error messages from perl. Rather, the
code must have been executed somehow. How could I prevent that?

--
Helmut Richter
 
Reply With Quote
 
 
 
 
Tim McDaniel
Guest
Posts: n/a
 
      01-20-2012
In article <(E-Mail Removed)>,
Ben Morrow <(E-Mail Removed)> wrote:
>
>Quoth Helmut Richter <(E-Mail Removed)>:
>> I'd like to do a perl syntax check as distinct from an execution. I
>> am well aware that there are many errors that cannot be found
>> without execution but I'd like to first remove the errors that can
>> be found without execution and *then* execute the script. My
>> attempt was using the -wc flag, but this has no effect whatsoever.

>
>It does. -c makes perl stop at the end of the main compile-time
>phase, exactly at the point where it stops invoking CHECK blocks and
>starts invoking INIT blocks.
>
>> > perl -wc ali.pl

>> [Fri Jan 20 16:51:56 2012] ali.pl: Variable "$body" is not imported at
>> ali.pl line 362.
>> [Fri Jan 20 16:51:56 2012] ali.pl: (Did you mean &body instead?)
>> Status: 500
>> Content-type: text/html
>>
>> <h1>Software error:</h1>
>> . . .
>>
>> The script is intended as CGI Script. The format of the error
>> messages, to wit the same format as web server log entries and a
>> status code 500, is hardly conceivable as pure syntax error
>> messages from perl. Rather, the code must have been executed
>> somehow. How could I prevent that?

>
>'use' statements happen at compile time. (That's the point.) This
>means that any code executed as part of a module's ->import method
>will be run even under -c. Presumably you are using some module
>(CGI::Carp?) that hooks into $SIG{__WARN__} (or something similar)
>and changes the warning format: the only way to stop that code from
>running is to comment out the 'use' statement.


I don't think the major problem is the log line format. His problem
statement is not so clear, but I think the problem is in the lines you
trimmed some of and that I restored above:

Status: 500
Content-type: text/html

<h1>Software error:</h1>
. . .

That appears to be running the actual code, despite (as your write)

>As a matter of good style, modules shouldn't do anything 'important'
>(open files, connect to databases, print output...) during compile
>time, but should wait to be asked. Since this *is* just a matter of
>style, though, there is nothing preventing modules from ignoring it
>if they choose to.


Just to be sure: Helmut, how is the CGI output being generated?
Surely it isn't
BEGIN {
print standard_HTTP_header();
print "<html>\n<head>\n"; ...
}
.... or is it?

--
Tim McDaniel, http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Helmut Richter
Guest
Posts: n/a
 
      01-20-2012
On Fri, 20 Jan 2012, Ben Morrow wrote:

> Assuming this is CGI::Carp, that output is almost certainly coming from
> the __DIE__ handler. This is running because perl is dieing at compile
> time, due to there being a fatal compile-time error (probably a syntax
> error) somewhere in the code. If the code were correct it would stop
> without producing any output.


Yes, it is certainly from "use CGI::Carp qw(fatalsToBrowser);" which I use
while debugging -- later without the fatalsToBrowser. It works fine for
errors at run time but not at compile time. It would be nice it did, just
sending the syntax errors to the browser screen, but it doesn't: the
browser gets an error 500 and the syntax errors go to the Nirwana.

Commenting out this line when doing syntax checks only is an acceptable
option.

Thank you.

--
Helmut Richter
 
Reply With Quote
 
Willem
Guest
Posts: n/a
 
      01-20-2012
Helmut Richter wrote:
) On Fri, 20 Jan 2012, Ben Morrow wrote:
)
)> Assuming this is CGI::Carp, that output is almost certainly coming from
)> the __DIE__ handler. This is running because perl is dieing at compile
)> time, due to there being a fatal compile-time error (probably a syntax
)> error) somewhere in the code. If the code were correct it would stop
)> without producing any output.
)
) Yes, it is certainly from "use CGI::Carp qw(fatalsToBrowser);" which I use
) while debugging -- later without the fatalsToBrowser. It works fine for
) errors at run time but not at compile time. It would be nice it did, just
) sending the syntax errors to the browser screen, but it doesn't: the
) browser gets an error 500 and the syntax errors go to the Nirwana.

Odd, it's supposed to send the compile time errors as well.
Have you turned off 'pretty errors' in your browser?


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
Reply With Quote
 
David Combs
Guest
Posts: n/a
 
      01-31-2012
In article <(E-Mail Removed)>,
Willem <(E-Mail Removed)> wrote:
>
>Odd, it's supposed to send the compile time errors as well.
>Have you turned off 'pretty errors' in your browser?


What browsers have a "pretty errors" feature?

Would emacs be one of them?

Thanks,

David

 
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
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
How to check the perl's syntax error before runing the code? sonet Perl Misc 6 06-17-2007 09:07 AM
Using Perl to check-out check-in in Clearcase mihirtr@gmail.com Perl Misc 0 12-22-2006 07:20 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM



Advertisments