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.

At 08:31 PM 6/29/05 -0700, Lyle Kopnicky wrote:
>Thanks folks.  I think I'll go with looks_like_number from 
>Scalar::Util.  I like to use library routines where possible.  I don't 
>know how I overlooked that, since I poked through Scalar::Util earlier.
>
>It just seems bizarre to me that something like that isn't a builtin.  I 
>mean, you can't even tell strings from numbers?  I'm used to working in 
>strongly typed languages.






--
REMEMBER THE WORLD TRADE CENTER         ---=< WTC 911 >=--
"...ne cede males"

00000100

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to