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

Monks!
How can use this code properly;

use CGI::Carp qw(fatalsToBrowser set_message); use vars qw($DEBUGGING); BEGIN { $DEBUGGING = 1; my $error_handler = sub { my $message = shift; print "<h1>I got a Problem</h1>"; print $message if $DEBUGGING; } set_message($error_handler); }

I am using it here and geting an error;
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser set_message); use vars qw($DEBUGGING); BEGIN { $DEBUGGING = 1; my $error_handler = sub { my $message = shift; print "<h1>I got a Problem</h1>"; print $message if $DEBUGGING; } set_message($error_handler); } my $string = "Fileserver with Samba and Printserver with CUPS"; print $string; exit;

Thanks!

Replies are listed 'Best First'.
Re: How to use CGI::Carp
by ikegami (Patriarch) on Jun 30, 2010 at 20:02 UTC

    Had you looked at your screen, you have would seen this error:

    syntax error at a.pl line 15, near "set_message" BEGIN not safe after errors--compilation aborted at a.pl line 16.

    Had you looked at your log file, you would have seen this error:

    Bareword found where operator expected at a.pl line 15, near "set_mess +age" (Missing semicolon on previous line?)

    (I don't know why it was split into two instead of being written to both places.)

    There's no semicolon between the 2nd and 3rd statement inside the BEGIN.

      How would re-write this code, based in what you commented on it?
        I would add the semi-colon I said was missing.
        Is this homework or something? That's the only indication I can think of that would make you miss ikegami explaining exactly what's wrong.