On Mon, 15 Jul 2002 19:14:32 +0900, Joel Rees wrote:

>I have some code that looks like this:
>
>       if ( int( $level ) == 1 )
>       {       push @testList, @originalTopPagePlusFlack;
>       }

Can $level ever be non-integer? If not, you may drop int() call.

>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)

That's not strict. That's -w.

>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.

Is there something special about 1 so that it's different from the empty
string? $level==1 seems like the top level to me. But, that aside...

You can test for truth value first, and only if that succeeds, test for
equality to 1. That way you're safe both for the empty string and for
undef.

        if ($level && $level == 1) { ... }

Alternatively, you can do

        if(($level || 0)==1) { ... }

but in this case I'd prefer the former.

-- 
        Bart.

Reply via email to