Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: use CGI::Carp qw(fatalsToBrowser); (is compile-time)

by tye (Sage)
on Apr 09, 2003 at 18:59 UTC ( #249354=note: print w/replies, xml ) Need Help??


in reply to Re: Re^2: use CGI::Carp qw(fatalsToBrowser); (is compile-time)
in thread use CGI::Carp qw(fatalsToBrowser);

A little experimentation reveals that perl throws syntax errors even before compilation really begins (or, at least before BEGIN blocks

No. You show me your experiement and I'll show you mine. ;) Heck, I'll show you mine anyway:

BEGIN { warn "Compiled first line of script"; } ....
gives
Compiled first line of script at - line 1. syntax error at - line 2, near "..."
or
use CGI::Carp qw( fatalsToBrowser ); ....
gives
Content-type: text/html <H1>Software error:</H1> <CODE>syntax error at - line 2, near &quot;...&quot; Execution of - aborted due to compilation errors. </C0DE> <P> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. [Wed Apr 9 11:36:09 2003] -: syntax error at - line 2, near "..." [Wed Apr 9 11:36:09 2003] -: Execution of - aborted due to compilatio +n errors.

Syntax errors in code that appears before the use CGI::Carp line will not be caught. For many CGI scripts, this boils down to just the #! line. But as pointed out elsewhere in this thread, CGI::Application was being used and the CGI::Carp was being used in the wrong place for it to take affect soon enough.

Perl code is compiled one-statement-at-a-time and so-called "compile-time" constructs get executed right after the statment they are contained in has been compiled. So there is no single "compile time" nor a single "run time". So each statement has one compile time and zero or more run times.

Things like BEGIN and use cause statements' run times to happen sooner while things like eval cause statements' compile times to happen later.

                - tye

Replies are listed 'Best First'.
Re: Re^4: use CGI::Carp qw(fatalsToBrowser); (is compile-time)
by Trimbach (Curate) on Apr 09, 2003 at 19:55 UTC
    And here's my experiment:
    #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); asfgafhafh print "Hello";
    yields
    bash-2.05a$ perl test.pl syntax error at test.pl line 7, near "asfgafhafh print" Execution of test.pl aborted due to compilation errors. bash-2.05a$
    ...which is just lovely if you have command-line access, but doesn't do you a lick of good through a browser (you'll just get a Error 500) even though the syntax error occurs after the use.

    Gary Blackburn
    Trained Killer

      For me, that exact code results in:

      Content-type: text/html <H1>Software error:</H1> <CODE>syntax error at - line 7, near &quot;asdfasefasdf print&quot; Execution of - aborted due to compilation errors. </C0DE> <P> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. [Thu Apr 10 09:01:20 2003] -: syntax error at - line 7, near "asfgafha +fh [Thu Apr 10 09:01:20 2003] -: [Thu Apr 10 09:01:20 2003] -: print" [Thu Apr 10 09:01:20 2003] -: Execution of - aborted due to compilatio +n errors.
      Perhaps you have a old/broken version of CGI::Carp? I'm using version 1.14.

                      - tye
        Well I might have a NEW/broken version of CGI::Carp. ;-) I'm using CGI::Carp version 1.24 on Perl 5.6.1 on Linux. I'll see if I can figure out what's going... it was certainly nice getting that whole Compile/Runtime thing straightened out, though. Thanks!

        Gary Blackburn
        Trained Killer

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://249354]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-01-29 14:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (74 votes). Check out past polls.

    Notices?