http://qs321.pair.com?node_id=609478

A simple way to test for numeric values. It basically asks perl whether it thinks the argument is numeric, by testing whether the argument is "numerically equal" to itself, and trapping any errors.

Update: Dang! I guess one could add !ref($x) && to the last line, but the joy is gone...

Update 2: Thanks Fletch; Scalar::Util::looks_like_number is the way to go.

sub is_numeric { use warnings FATAL => qw( numeric uninitialized ); local $@; my $x = shift; return eval { $x == $x }; }