in reply to Exploiting Perls idea of what is a number

use Scalar::Util qw(looks_like_number); sub compare { my ($x, $y) = @_: if (looks_like_number($x) && looks_like_number($y)){ return $x == $y; } else { return $x eq $y; } }

Replies are listed 'Best First'.
Re^2: Exploiting Perls idea of what is a number
by syphilis (Archbishop) on Jul 08, 2008 at 14:00 UTC
    My first thoughts were in the direction of Scalar::Util::looks_like_number, too ... but that always leads to the consideration of what should be done with strings like '3567rubb13h'. Perl will numify that to 3567, yet Scalar::Util::looks_like_number will tell you that it *doesn't* look like a number. (It amuses me that perl is capable of bestowing a non-zero numerical value on something that doesn't even "look like a number".)

    Does rovf want such a string to be kept as a string ? or should it instead be numified to 3567 ?

    Cheers,
    Rob
      what should be done with strings like '3567rubb13h'

      At the moment, this type of strings won't be a problem, but if they appear (for example, with (the same) measurement unit appended, such as "450KB"), it would be fine to have them interpreted as number.

      -- 
      Ronald Fischer <ynnor@mm.st>