shemp has asked for the wisdom of the Perl Monks concerning the following question:
I guess maybe this gets beyond the scope of truth vs. false and gets into Perl's loose variable typing, and how they interact. Anyway, any advice for how to properly explain Perl's concepts of truth and false?my $string = "0.0"; print "true\n" if $string; # true my $x = 3 + $string; print "true\n" if $string; # true $string += 0; print "true\n" if $string; # false
Update:
Someone mentioned that i might want to test $x in the second example. Actually, i want to test string. That one is an example of using $string in a numeric context, but it doesn't set the internal falg for $string to say that it was most recently used as a number. (sorry for butchering this explanation, i don't know exactly how the internals work for scalars in perl)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Explaining Perl truth to beginners
by davidrw (Prior) on Nov 21, 2005 at 19:03 UTC | |
|
Re: Explaining Perl truth to beginners
by Tanktalus (Canon) on Nov 21, 2005 at 19:06 UTC | |
|
Re: Explaining Perl truth to beginners
by merlyn (Sage) on Nov 21, 2005 at 20:26 UTC | |
|
Re: Explaining Perl truth to beginners
by Roy Johnson (Monsignor) on Nov 21, 2005 at 19:05 UTC | |
by ysth (Canon) on Nov 22, 2005 at 12:51 UTC | |
|
Re: Explaining Perl truth to beginners
by philcrow (Priest) on Nov 21, 2005 at 19:05 UTC |