http://www.perlmonks.org?node_id=415114


in reply to Does it look like a number?

Lots more on this topic came up recently. See Detecting if a scalar has a number or string, which includes a lot of discussion about how to treat objects that overload like numbers. I personally like Re^3: Detecting if a scalar has a number or string by davido, which ducks a lot of the issues and tests to see if a given input would generate a warning if used in arithmetic -- which is what I usually find myself wanting to check when I'm being given user input (as opposed to whether something is represented internally as a number or string).

-xdg

Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.