Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

Comment on Re: undef-safe equality
Download Code

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 rifling through the Monastery: (2)
As of 2015-11-27 00:57 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (710 votes), past polls