I need to dynamically do comparisons tests on an array of values...some
strings, some numeric. One snag I hit is comparing the occasional numeric
values. Using "eq" as the comparison operator fails on comparisons like
"45.0" vs "45".
Is there a way to determine if a scalar value is indeed numeric
Paul Rogers [perl-users AT coservers DOTnet] wrote:
> I need to dynamically do comparisons tests on an array of
> values...some strings, some numeric. One snag I hit is
> comparing the occasional numeric values. Using "eq" as
> the comparison operator fails on comparisons like
> "45.0" vs "45".
ore or
less mimics the IsNumeric VB function:
if ($mytestvar =~ /^-?(\d+\.?\d*|\.\d+)$/) {
print "This is a numeric value.";
}
Thanks,
Paul ---
- Original Message -
From: Andy Bach
To: "Paul Rogers" <[EMAIL PROTECTED]>
Sent: Tuesday, November 16, 2004 6:03 PM
Subject:
CTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Rogers
Sent: 17 November 2004 02:44
To: Perl-Win32-Users
Subject: Re: numeric vs string scalars...difference?
Hi Andy,
Thanks for your response.
For clarification I'm doing equality comparisons. Thus...
$x = '45.0';
$y = '45&
ssage -
From: "Paul Sobey" <[EMAIL PROTECTED]>
To: "Paul Rogers" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, November 17, 2004 4:16 AM
Subject: RE: numeric vs string scalars...difference?
Hi,
Isn't eq a string comparison? Try using
2004 1:29 PM
> To: [EMAIL PROTECTED]
> Subject: Re: numeric vs string scalars...difference?
>
>
> Hi Paul,
>
> You are absolutely right. However, the real problem was that
> I had to
> dynamically determine whether to use == or eq...thus I needed
> a way of
> reliab
From: "Thomas, Mark - BLS CTR" <[EMAIL PROTECTED]>
To: "'Paul Rogers'" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Wednesday, November 17, 2004 2:07 PM
Subject: RE: numeric vs string scalars...difference?
How about 1.02e12?
If you wan