Multiple methods.
- Do error checking before that return... to prevent $alldata->{cont} and $_->{cont} from being undefined. Or use logic to make sure that if one or both are undefined, it never makes it to that line. This is the only solution that will help you discover the "why" of why the warning is occurring; the best is to prevent the data from being bad before getting here.
- if you want to have undef ne undef to be false, then you could say
$alldata->{ cont }//'<undef>' ne $_->{ cont }//'<undef>' (see choroba's reply): the defined-or operator // will stop at the first if it's defined, else use the second; by having both fall back to <undef> as the value, if both are undefined, they will resolve to the same string, and so the full expression will resolve down to '<undef>' ne '<undef>', which evaluates to false
- if you want to have undef ne undef to be true, then you could say
$alldata->{ cont }//'<undef1>' ne $_->{ cont }//'<undef2>': this time, they resolve to different strings, so the two different strings will not be equal.
- you can say no warnings 'uninitialized'; at the smallest block, so it affects as little as possible -- I would recommend the line right before the return... line, and only if that line is somewhere in a logical block (enclosed in {}).
The first is the best. The second and third can be used if there's some valid reason for those variables to be undefined, and you just want a known action if both are undefined. The fourth is just an indication that the programmer is unwilling to look into why the variables have undefined values, and just wants to sweep the problem under the rug and pretend there isn't a problem when there really is.
edit: // has lower precedence than I remembered, so use parentheses as
choroba shows below.
edit2: fix typo in username (I got it right 1/2 times, so that counts for something). Thanks LanX
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.