in reply to The error says the value is uninitialized, but it works anyway

Incidentally, if there is a possibility that a value could be undef, you can use the defined() function to reliably test for this. You can use "short-circuit expression evaluation" to great advantage here:

if (defined($foo) && ($foo eq $bar)) ...

If defined() returns False, evaluation of the expression will terminate immediately and the eq will not be performed. This will avoid any ambiguity that might be caused by Perl's string-casting, and it also alerts the subsequent programmers that undef is a possibility.

  • Comment on Re: The error says the value is uninitialized, but it works anyway