Re: [MacPerl-AnyPerl] testing numericity

[email protected] (Joel Rees) Tue, 16 Jul 2002 15:47:07 +0900
Newsgroups perl.macperl.anyperl
Message-ID <[email protected]>
Thanks, Chris, Bart, and Paul. Got it solved:

	if ( scalar @ARGV > 0 )
	{	@testList = @ARGV;
	}
	if ( $level =~ m/^1.*/ )
	{	push @testList, @originalTopPagePlusFlack;
	}
	elsif ( $level =~ m/^2.*/ )
	{	push @testList, @anotherTopPagePlusFlack;
	}
	elsif ( scalar @ARGV == 0 )	# still feels funny
	{	@testList = @basicTopPage;
	}
	elsif ( $level =~ m/^0.*/ )	# 0
	{	push @testList, @basicTopPage;
	}

Here's what it originally looked like (and I should have put it in the
original post).

	if ( scalar @ARGV > 0 )
	{	@testList = @ARGV;
	}
	if ( $level == 1 )
	{	push @testList, @originalTopPagePlusFlack;
	}
	elsif ( $level == 2 )
	{	push @testList, @anotherTopPagePlusFlack;
	}
	elsif ( scalar @ARGV == 0 )
	{	@testList = @basicTopPage;
	}
	elsif ( $level != '' )	# 0 (or anything not 2)
	{	push @testList, @basicTopPage;
	}


The thing that was messing me up was changing the first two tests and
failing to change the last one.

Maybe I should go back to teaching English for a living.

I wrote

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

-- 
Joel Rees <[email protected]>