Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

'use strict' causing me an error

by nysus (Parson)
on May 25, 2001 at 10:18 UTC ( [id://83237]=perlquestion: print w/replies, xml ) Need Help??

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

What's up dudes? Another late night. I'm having a problem here. The following bit of code I'm using is generating an error with 'use strict':
BEGIN { use CGI::Carp qw(carpout fatalsToBrowser); open (LOG, ">errorlog.txt") or die("Unable to open errorlog.txt: $!\n"); carpout(LOG); }
The error code reads:
BEGIN not safe after errors--compilation aborted at /site_path/cgi-bin +/event/eventform.cgi line 12.
Any ideas?
Note: Line 12 is the closing brace in the code above.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar";
$nysus = $PM . $MCF;

Replies are listed 'Best First'.
Re: 'use strict' causing me an error
by japhy (Canon) on May 25, 2001 at 10:28 UTC
    The documentation suggests you do:
    You can pass filehandles to carpout() in a variety of ways. The "correct" way according to Tom Christiansen is to pass a reference to a filehandle GLOB:
    carpout(\*LOG);


    japhy -- Perl and Regex Hacker
      Tried it, still getting error.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar";
      $nysus = $PM . $MCF;

        the code runs fine for me under use strict;, probably your error is somewhere else in your code, or you're running some really weird ancient version of perl.
        supplying a link to the whole code and giving your version of perl and your plattform might help!

        cheers
        snowcrash
Re: 'use strict' causing me an error
by chipmunk (Parson) on May 25, 2001 at 18:28 UTC
    The error that you quoted only says that the BEGIN block couldn't be compiled; it doesn't say why the BEGIN couldn't be compiled.

    This is the same situation that I explained to you in Re: Re: Re: Re: Gettin ALL errors with carp module; CGI::Carp qw(fatalsToBrowser) only captures the generic "Compilation failed" error message, not all the warnings that explain why compilation failed. The only difference is this time the compilation problems are in a BEGIN block.

    Once again, you can easily avoid this situation by testing your scripts from the command line to make sure they compile, before running them through the web server. Otherwise, check the server error logs for all the compilation warnings.

Re: 'use strict' causing me an error
by stuffy (Monk) on May 25, 2001 at 10:30 UTC
    I'm not an expert or anything, but have you tried removing the paranthesis around the "Unable to open errorlog.txt: $!\n"
    or die "unable to open errorlog.txt: $!\n";
    I'm not sure if that maters or not, I just know that I don't use them in my code.

    Stuffy

    update:

    Opps, I was wrong, oh well, can't blame a guy for trying
Re: 'use strict' causing me an error
by nysus (Parson) on May 25, 2001 at 10:54 UTC
    Problem solved. I think it was the first problem and I forgot to hit save. Need to go to bed.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar";
    $nysus = $PM . $MCF;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-19 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found