[ABE.pm] trapping warnings

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Thu Oct 4 17:31:54 PDT 2007


* "Faber J. Fedor" <faber at linuxnj.com> [2007-10-04T20:03:56]
>   $sum = $indexTable2->elm($i, "weight");
>   while ($sum <= $captPercentile) {
>       $sum += $indexTable2->elm($i+1, "weight");
>       $bottom_count ++;
>       $i++;
>   }
> 
> [ ... ]
> Row index out of range [0..-1]Use of uninitialized value in addition (+) at
> /home/sqa/bin/processMonthlyData.pl line 497.
> [ ... ] 
> 
> How do I trap this and DIE with an error message?

Rather than using an actual SIG{__?__} handler, consider catching that problem
before it occurs:

  while ($sum <= $captPercentile) {
    my $next_value = $indexTable2->elm($i + 1, "weight");
    confess "didn't get a positive number from table" unless $next_value > 0;

    $sum += $next_value;
    $bottom_count++
    $i++;
  }

-- 
rjbs


More information about the ABE-pm mailing list