I am trying to print a scalar(string or numeric) only when it is not equal to an empty string "" and 0 . The code below works correctly for $key,$key2 and $key3 but not $key1;
#!/usr/bin/perl $key = 1; $key1 = "test"; $key2 = ""; $key3 = 0; if (($key ne "") && ($key != 0)){ print "\n$key\n"; } OUTPUT : Correct For $key : 1 Incorrect For $key1 : Correct For $key2 : Incorrect For $key3 :
In reply to If condition logic yielding partially correct output by perlpal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |