On Tue, Jul 03, 2007 at 02:42:29AM -0400, Chas Owens wrote: > On 7/3/07, Paul Johnson <[EMAIL PROTECTED]> wrote: > snip > >And, in this case, more accurate. Unless you know something the rest of us > >don't. > snip > > The trinary operator (?:) returns the value of either the true or > false portion depending on the conditional portion, so putting print > in both the true and false portions is redundant. Also 0 is one of > the 5ish false values* so !$var1 is the same thing** as $var1 == 0 and > 1 is one of the infinite true values*** so $var2 is equivalent to > $var2 == 1 so long as you are testing for truth rather than the > specific value 1. > > #!/usr/bin/perl -l > > use strict; > use warnings; > > my $var1 = 0; > my $var2 = 1; > print "should print hai:", !$var1 && $var2 ? "hai" : "bye"; > > $var1 = 1; > print "should print bye:", !$var1 && $var2 ? "hai" : "bye"; > > $var2 = $var1 = 0; > print "should print bye:", !$var1 && $var2 ? "hai" : "bye";
Even with these assumptions and caveats, I think you may have forgotton to consider strings, as well as such esoterica as 0e0 and "0 but true". But apart from matters such as having a firm specification or testing boundary conditions, I fear we're starting to veer away from what might be considered useful on a beginners list, so I'll leave it there for now. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/