Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by tye (Sage)
on Dec 15, 2004 at 18:54 UTC ( [id://415153]=note: print w/replies, xml ) Need Help??


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        

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://415153]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found