Nathan Wiger writes:
> print "Welcome back, $first $middle $last!\n";
>
> My question: What good is this warning in most contexts, anyways?
> Really. Honestly. If you cared about the value, you would already be
> checking it, right? Probably with something like this:
>
> die "Fatal: Can't continue with \$var unset!" unless $var;
Tee hee! The point of the warning is to tell you that you should be
checking it and aren't. You're assuming the variable has a value,
because you are treating it like a string. But the variable doesn't
have a value. This is probably an error.
Either you didn't give the variable a value (for example, because it's
9-5 you didn't call the "authorize user" subroutine that would have
set the $username variable) or you called a function to get a value
for the variable, but the function returned undef to indicate an error
and you never checked for that. Both of these situations are almost
always errors.
Saying:
my $middle = '';
if you want to allow for the situation where there isn't a middle
initial given isn't that much of a hardship, especially when you
consider all the things that might go wrong.
I've never had an "uninitialized value" warning that wasn't my own
damn fault. At least, not that I can remember.
Nat