testing numericity

[email protected] (Joel Rees) Mon, 15 Jul 2002 19:14:32 +0900
Newsgroups perl.macperl.anyperl
Message-ID <[email protected]>
I have some code that looks like this:

	if ( int( $level ) == 1 )
	{	push @testList, @originalTopPagePlusFlack;
	}

When it runs with an empty string in $level, (using strict) I get this
warning:

----------------
Argument "" isn't numeric in int at autohits.pl line 352 (#1)
    (W numeric) The indicated string was fed as an argument to an operator
    that expected a numeric value instead.  If you're fortunate the message
    will identify which operator was so unfortunate.

Argument "" isn't numeric in numeric ne (!=) at autohits.pl line 352 (#1)
----------------

I've tried using index() and an RE instead of the numeric compare, but
those give me nearly the same warning. (??) So I am wondering how to get
at a value that may be either numeric or an empty string.

Thought of using a subroutine, but then I think the subroutine is going
to have the same problem if I try to generalize to handle non-empty
strings that don't convert. I can simply skip generalizing, but I am
wondering if there is something similar to php's is_numeric() (or
whatever that was).

Any suggestions?

-- 
Joel Rees <[email protected]>