Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: undef-safe equality

by tlm (Prior)
on Apr 21, 2005 at 19:50 UTC ( #450178=note: print w/ replies, xml ) Need Help??


in reply to undef-safe equality

In this case, I think dragonchild's solution is the way to go, but in general, you can switch warnings off locally and selectively; e.g.:

{ no warnings 'uninitialized'; if ( $ret->{'val1'} eq $this->{'val1'} ) { # ... } }

To figure out the name of the warnings to turn off, run your code with the diagnostics pragma. Then you'll get extended warning messages like:

Use of uninitialized value in string eq at -e line 1 (#1)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
    To suppress this warning assign a defined value to your variables.

    To help you figure out what was undefined, perl tells you what operation
    you used the undefined value in.  Note, however, that perl optimizes your
    program and the operation displayed in the warning may not necessarily
    appear literally in your program.  For example, "that $foo" is
    usually optimized into "that " . $foo, and the warning will refer to
    the concatenation (.) operator, even though there is no . in your
    program.
The (W uninitialized) bit tells you the name of the desired argument to no warnings.

the lowliest monk


Comment on Re: undef-safe equality
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-09-20 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls