perlpal has asked for the wisdom of the Perl Monks concerning the following question:
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 :
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: If condition logic yielding partially correct output
by JavaFan (Canon) on Aug 13, 2009 at 10:54 UTC | |
|
Re: If condition logic yielding partially correct output
by Old_Gray_Bear (Bishop) on Aug 13, 2009 at 11:02 UTC | |
by dsheroh (Monsignor) on Aug 13, 2009 at 11:27 UTC | |
by Anonymous Monk on Aug 13, 2009 at 11:12 UTC | |
|
Re: If condition logic yielding partially correct output
by Utilitarian (Vicar) on Aug 13, 2009 at 10:54 UTC | |
|
Re: If condition logic yielding partially correct output
by Anonymous Monk on Aug 13, 2009 at 11:07 UTC | |
|
Re: If condition logic yielding partially correct output
by bobf (Monsignor) on Aug 14, 2009 at 03:00 UTC |