in reply to on to better coding (no uninitialized values)

Assuming that your undefined values are coming in from subroutine calls, or from something like CGI.pm, one way I do it is to set a default value for it using the powerful ||= operator:
sub do_something { my ( $file ) = @_; $file ||= "default.txt"; ... }
If $file is defined, no further action is taken, since || short-circuits out on the true value. Otherwise, it sets $file to the default name given. Any time further, there's very little chance that $file will be undef'd.

The only time this doesn't work is if a value 0 or the empty string ('') is passed, since these also evaluate to false. In cases where these are possible values, I then do defer to defined to make sure that the values aren't overwritten.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
It's not what you know, but knowing how to find it if you don't know that's important

Replies are listed 'Best First'.
Re: Re: on to better coding (no uninitialized values)
by echo (Pilgrim) on Aug 23, 2001 at 21:16 UTC
    The ||= idiom is useful for providing default values. However I've seen programmers use it extensively, precisely to get rid of the use of uninitialized value warning. I think that is not a good strategy, because it will hide bugs. A variable that is used without having been initialized illustrates a logic bug, and the warning comes in handy to warn us of this bug. Adding ||= "" to the offending line gets rid of the warning, but not of the bug. Indeed it is a useful idiom if the concept of a default value makes sense for a particular variable, but it shouldn't be abused.
(ichimunki) Re x 2: on to better coding (no uninitialized values)
by ichimunki (Priest) on Aug 23, 2001 at 23:56 UTC
    I prefer to use something like:
    sub do_something { my $file = shift || 'default'; }

    since this is also conveniently converted to perform an action:
    sub do_something { my $file = shift or warn "empty parameter\n"; }

    YMMV.