Chris Wagner wrote: > Wow there's been a lot of heavy duty code proposed to do something so > simple. The answer is in how Perl converts between the two. > > print "is a number" if $var eq $var + 0; > print "not a number" if $var ne $var + 0; > > Say $var is "bob". In the first case we see if "bob" is string equal to bob > + 0 or is "bob eq 0". Obviously not. > Say $var is 5. In the second case we see if "5" is not string equal to 5 + > 0 or is "5 ne 5". > > In this setup we're forcing the variable into numeric context and then back > into string context. How the variable survives that procedure depends on > whether it is number like or not number like.
Some of us use strict and warnings. What happens with this ? : use strict; use warnings; my $var = undef; print "is a number" if $var eq $var + 0; print "not a number" if $var ne $var + 0; and my $var = 'bob'; print "is a number" if $var eq $var + 0; # will give a warning if $var not a number -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs