Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2018-02-25 12:28 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.