Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by Anonymous Monk
on Aug 19, 2019 at 17:30 UTC ( #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
Node Status?
node history
Node Type: note [id://11104696]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2019-09-20 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (253 votes). Check out past polls.

    Notices?