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