Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by Anonymous Monk
on Aug 19, 2019 at 17:30 UTC ( [id://11104696]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104696]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-24 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found