Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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
The (W uninitialized) bit tells you the name of the desired argument to no warnings.

the lowliest monk

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2016-10-27 23:26 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (372 votes). Check out past polls.