Title: RE: Test if string is a number?
Chris Wagner wrote, on Thu 6/30/2005 12:41

: At 09:48 AM 6/30/05 -0500, Joe Discenza wrote:
: >Except if $var is, say, '0.00'. Then $var + 0 is '0', and won't eq $var.
:
: 0.00 is not a valid internal representation of a number.  That can only
: exist as a string.  Same goes for "1e7".  That is a print formated number,
: not a valid internal number.  $var = 1e7 and print $var -> 10000000. $var =
: 0.00 and print $var -> 0.  If u want to include "numberish" strings then u
: need some eval's to digest the various number formats.  ... if eval $var eq
: $var + 0;

IIRC (no longer have the message), the OP had *string* data to check for numerics. Your method would miss, say, a CSV full of prices if they ended ".00" or ".50".

I bet you're right that "eval($var) eq $var + 0" works; have you benchmarked it against all the other (regex, e.g.) methods presented?

Joe

 

==============================================================
          Joseph P. Discenza, Sr. Programmer/Analyst
               mailto:[EMAIL PROTECTED]
 
          Carleton Inc.   http://www.carletoninc.com
          574.243.6040 ext. 300    fax: 574.243.6060
 
Providing Financial Solutions and Compliance for over 30 Years
 
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to