in reply to Reviews Quest

A lot of monks here strongly recommend the use of -w (however, the use warnings pragma should now be used) and use strict.

Something I think that most people haven't touched on is the usefulness of the CGI::Carp module.

When you've been writing a CGI script, how many times has it run from the shell fine, only to give you the dreaded '500 Internal Server Error'. CGI::Carp writes a $SIG{__DIE__} handler so that die() calls are handled fine, and you get the same sort of error message in your browser that you would when running your script from the shell.

So, make sure you:

use CGI::Carp qw(fatalsToBrowser)
in all your CGI scripts. It has saved me literally HOURS of debugging time.

Replies are listed 'Best First'.
RE: CGI::Carp
by Ovid (Cardinal) on Jul 08, 2000 at 21:33 UTC
    I wholeheartedly agree with one minor reservation: remember that this is a development tool. Using CGI::Carp qw(fatalsToBrowser) in production can reveal a lot of information to a would-be hacker in the event that he/she can crash your script. Don't leave it in there!
RE: CGI::Carp (use warnings?)
by ybiC (Prior) on Jul 08, 2000 at 22:26 UTC
    "however, the use warnings pragma should now be used"

    Fairly extensive search turned up only the vague "new use warnings pragma is in the works" from perlfaq7 ca.1999

    Now I'm curious - what's use warnings do that -w doesn't ?
      My understanding is that as of 5.6 -w on the command line and use warnings in your code are identical. Both "enable many useful warnings". As of 5.6 (maybe earlier, I'm not sure) there is a -W command line option that will "enable all warnings". I do not know if there is a use equivalent to -W.
        As far as I know, the use warnings pragma was introduced as:

        - it is easier for people who are on non 'shebang supporting' systems to use.
        - it can be disabled for certain blocks etc. Here's an introduction to the new pragma from the What's new in Perl 5.6 page:

        Lexical Warnings

        'Death is not good. I reject death. I will stay away from trucks today.' - lwall

        The way Perl generates warnings has also been completely revised: as a replacement for the -w flag and the $^W special variable, the warnings pragma gives you more flexibility about what warnings you receive and when. In terms of what, you can now specify warnings by category: there are a bunch of standard categories, such as 'syntax', 'io', 'void', and modules will be able to define their own categories. You can also choose to escalate any categories of warning into a fatal error. As for when, the pragma is lexically scoped, so you can switch it on and off as you wish:

        use warnings; $a = @a[1]; # This generates a warning. { no warnings; $a = @a[1]; # This does not. }
        See perllexwarn for how to use this from programs and modules.
        D'oh, the proper post is 'below' this one, sorry

        As far as I know, the use warnings pragma was introduced as:

        - it is easier for people who are on non 'shebang supporting' systems to use.
        - it can be disabled for certain sections of code, e.g.

        use strict; use warnings; print $foo; # Warning here, undefined value no warnings; print $foo; # No warning now use warnings; print $foo; # Warning again
        On systems that don't support the UNIX shebang, it is a pain having to manually type in

        perl -w foo.pl

        every time you want warnings. If you can just use the pragma, it is easier.