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".
> 
> Is there a way to determine if a scalar value is indeed numeric?

Look in the Perl FAQ for various regex tests for a numeric.
Then do this (pseudo-code):

  if ( is_numeric( $left) && is_numeric( $right ) )
  {
    $is_equal = $left == $right;
  }
  else
  {
    $is_equal = $left eq $right;
  }

That is, only use the numeric equality test '==' if both values
are numeric. Otherwise use the string equality test 'eq'.

--
Mike Arms


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

Reply via email to