Re: Test if string is a number?

2005-06-30 Thread $Bill Luebkert
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

Re: Test if string is a number?

2005-06-30 Thread Chris Wagner
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

RE: Test if string is a number?

2005-06-30 Thread Thomas, Mark - BLS CTR
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; That fails on 1e7. ___

RE: Test if string is a number?

2005-06-30 Thread Joe Discenza
Title: Re: Test if string is a number? Chris Wagner wrote, on Thu 6/30/2005 08:48 : 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

Re: Test if string is a number?

2005-06-30 Thread $Bill Luebkert
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

Re: Test if string is a number?

2005-06-30 Thread Siebe Tolsma
Title: Re: Test if string is a number? How about regexp? /^\-?(\d+\.?\d*|\.\d+)$/ - Original Message - From: Joe Discenza To: Chris Wagner ; perl-win32-users Sent: Thursday, June 30, 2005 4:48 PM Subject: RE: Test if string is a number? Chris Wagner

RE: Test if string is a number?

2005-06-30 Thread Andreas.Kamentz
: Test if string is a number? How about regexp? /^\-?(\d+\.?\d*|\.\d+)$/ - Original Message - From: Joe Discenza To: Chris Wagner ; perl-win32-users Sent: Thursday, June 30, 2005 4:48 PM Subject: RE: Test if string is a number? Chris Wagner wrote, on Thu 6/30/2005 08:48 : Wow there's

RE: Test if string is a number?

2005-06-30 Thread Chris Wagner
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.

RE: Test if string is a number?

2005-06-30 Thread Thomas, Mark - BLS CTR
[EMAIL PROTECTED] wrote: 0.00 is not a valid internal representation of a number. That can only exist as a string. I think u need to re-read the subject of this thread. - Mark. ___ Perl-Win32-Users mailing list

RE: Test if string is a number?

2005-06-30 Thread Joe Discenza
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

RE: Test if string is a number?

2005-06-30 Thread Chris Wagner
At 12:16 PM 6/30/05 -0500, Joe Discenza wrote: 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? I haven't benchmarked it but I can garuntee that it's faster than a regex. Anything's faster than that. ;) This

RE: Test if string is a number?

2005-06-30 Thread Joe Discenza
Title: RE: Test if string is a number? Chris Wagner wrote, on Thu 6/30/2005 14:41 : At 12:16 PM 6/30/05 -0500, Joe Discenza wrote:: 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?::

Re: Test if string is a number?

2005-06-30 Thread $Bill Luebkert
Joe Discenza wrote: Chris Wagner wrote, on Thu 6/30/2005 14:41 : At 12:16 PM 6/30/05 -0500, Joe Discenza wrote: : 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? : : I haven't benchmarked it but I can

RE: Test if string is a number?

2005-06-30 Thread Chris Wagner
At 02:28 PM 6/30/05 -0500, Joe Discenza wrote: Regex is pretty fast. Eval is usually pretty slow. Yeah ur right about the eval. I did a triple head to head with ur regex and eval/no eval. The eq without the eval demolishes all. Rate evalRE noeval eval3397/s -- -87%

Re: Test if string is a number?

2005-06-29 Thread Lyle Kopnicky
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