in reply to Re: How to conditionally use CGI::Carp?
in thread How to conditionally use CGI::Carp?

You said to use:

BEGIN { if ( ... ) { require 'CGI::Carp'; CGI::Carp->import('fatalsToBrowser'); } }

But my perl doesn't like the single quotes. And, since I want to import more than one function, I used "import" directly, resulting in:

require CGI::Carp; import CGI::Carp qw(fatalsToBrowser set_message carpout); set_message(\&handle_error);

Next, you said:

I typically test for the existance of $ENV{'SERVER'} or any of the other environmental variables

Problem is, $ENV is completely empty when I run either from the tty or as a cgi. This surprises me, too, frankly. I test for anything, and always get zilch.

Replies are listed 'Best First'.
Re^3: How to conditionally use CGI::Carp?
by argv (Pilgrim) on May 06, 2005 at 05:05 UTC
    OK, now waitaminute.... I've got an update, and hence a modification to my previous reply to this. That is, I said that my %ENV had nothing in it. I was wrong--it DOES. The reason I was mistaken is because I was trying to be tricky. Follow me on this because it gets circuitous--thus, interesting. I used the following code:

    my $ip = $ENV{'REMOTE_ADDR'}; BEGIN { if ( $ip ) { [...] } }

    That didn't work, which is no surprise, because the BEGIN block runs before the code runs, so $ip has no value when the BEGIN block runs. But, if that's the case, why does a print statement print? I take up this question in What is the scope of BEGIN? Or... when does it "begin?"..