in reply to Preventing Use of uninitialized value

Multiple methods.

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

Replies are listed 'Best First'.
Re^2: Preventing Use of uninitialized value
by choroba (Cardinal) on Sep 20, 2021 at 19:59 UTC
    Removing spaces around // doesn't change its (unfortunate) precedence. Parentheses are needed.
    ($alldata->{cont} // '<undef>') ne ($_->{cont} // '<undef>')
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      ++Thanks. I should've tested before posting, but thought it was easy enough syntax to get without verification; my bad. (original node edited to not propagate misinformation)