True enough, I thought I had been booted off the list or something...


Just wanted to comment, that if you roll your own number detector, and you
want it compatible with *nix Perl, you should count as a number any string
beginning with letters "inf" (case insensitive).

This is an undocumented "feature" which I have used in demo code for
sorting. "inf" is treated as a number larger than any other number besides
"inf".

On Windows however, "inf" is just another string.

Just wanted to complicate things a bit!

Cheers!


On Thu, 18 Oct 2001, Selector, Lev Y wrote:

> Folks,
>
> It was long time - no messages (on this list).
> Is everybody OK?
> I am working in downtown New York City -
> and still can smell burning outside the building:
>
>    http://www.spaceimaging.com/ikonos/wtc0915_1280.jpg
>
> I have a (simple) Perl question.
> Is there a standard function in perl which can tell me
> if a string represents a valid number?
> (including integer, with decimal point and scientific notaion with "e").
>
> Of course, I can write one myself.
> For example, something like this
> (if we are not considering hex, octal and binary):
> # ---------------------------------------------
> sub isNumber {
>   my $ss = shift;
>   return 1 if $ss =~ /^[+\-]?\d*.?\d+$/;
>   return 1 if $ss =~ /^[+\-]?\d*.?\d+e[+\-]?\d+$/i;
>   return 0;
> }
>
> for (  qw[ 1  -1.0  1.0e-10  10abc ]  ) {
>   print "$_ -> ", isNumber($_), "\n";
> }
> # ---------------------------------------------
>
> But may be there is a standard solution already?
>
> POSIX module has several functions.
> For example, isdigit returns 1 if argument consists only of digits.
> This covers only integer numbers.
> There are other functions, like strtoi, strtol, strtod to convert a string
> to integer, long, or double. But these functions are specific to their
> nubmer type.  What I need is a combination of them.
>
> Any recommendations?
>
> Warmest Regards
> ----
> Lev Selector
> New York,
> t. 212-902-3040
>
>
>
>

Reply via email to