in reply to Re^3: Detecting if a scalar has a number or string
in thread Detecting if a scalar has a number or string

Note that looks_like_number() tells you exactly the same thing, just without all of the overhead. (:

- tye        

  • Comment on Re^4: Detecting if a scalar has a number or string

Replies are listed 'Best First'.
Re^5: Detecting if a scalar has a number or string
by davido (Cardinal) on Dec 15, 2004 at 23:24 UTC

    For the record, you're absolutely right. Scalar::Util's looks_like_number() is 655% faster than my eval trap fatal warning approach. But for some reason I do get a sort of a kick out of the idea of letting perl (the interpreter) tell me if a scalar is a number, rather than Perl (the script). Consider my solution purely an academic enveavor, and use the module for production code.

    The benchmark script:

    The results:

    Rate Seems Looks Seems 38.8/s -- -87% Looks 297/s 665% --

    Dave