On 3/25/11 Fri Mar 25, 2011 11:15 AM, "Chris Stinemetz" <chrisstinem...@gmail.com> scribbled:
> I am getting the warning: > > Argument "" isn't numeric in numeric lt (<) at ./DOband.pl line 22, > <$fh> line 52411. > > It seems to be directed to the below ternary operator: > How can I include in the ternary to ignore all non numeric values in > the elements $cell and $chan? > > my $carr = > > ( $cell < 299 && $chan == 175 ) ? 2 : > ( $chan == 1025 ) ? 2 : 1 ; #nested ternary operator > According to the error message, $cell contains "", the empty string. Perl is objecting to the attempt to compare that value with 299. The solution is to either 1) don't attempt the comparison if $cell is an empty string or 2) set $cell to a valid numerical value if it contains an empty string. For the former case, you can use an if statement: if( $cell ) { ... but that will eliminate cases where $cell has a possibly valid value of zero. For the latter case, the value zero is a natural substitute, but only you can say if this is a valid thing to do in your situation. The normal way to do this is: $cell = $cell || 0; This assigns numerical zero to $cell if it's current value evaluates to false (undef, 0, or ''). This may be shortened to: $cell ||= 0; This substitution can also be done in some cases when a value is assigned to the variable, e.g.: $cell = $data[1] || 0; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/