mpettis has asked for the wisdom of the Perl Monks concerning the following question:

Update: This is solved. The note that 'Runtime warnings triggered in elsif conditions are reported with the line number of the original if condition.' was the key. Below is the change to the 'elsif' statement I made (making it the trinary operator). Thank you again to everybody who responded!

elsif (($cur[2]) > ($sec[2] ? $sec[2] : 0)) { ----------------------------------------------

Hi, I have the following code snipped that generates warnings in places that I cannot find a rhyme or reason for:
135 # new record is the highest 136 print "Begin: i=[$i], cur[2]=[",$cur[2],"], win[2]=[", +$win[2], "]", "\n"; 137 if ($cur[2] > $win[2]) { 138 $top2{$key1}{$key2} = [$votes_office_ttl,@cur,@win] +; 139 } 140 elsif (0+$cur[2] > 0+$sec[2]) { 141 $top2{$key1}{$key2} = [$votes_office_ttl,@win,@cur] +; 142 }; 143 print "End: i=[$i], cur[2]=[",$cur[2],"], win[2]=[", $w +in[2], "]", "\n";
And I get the following warning emitted interleaved with my print statements:
Begin: i=[32], cur[2]=[20], win[2]=[100] Argument "" isn't numeric in addition (+) at ./x.pl line 137, <$fhin> +line 32. End: i=[32], cur[2]=[20], win[2]=[100]
I don't understand why the boolean statement at 137 is being emitted... you can see the values of the variables going into the boolean comparison beforehand. In addition, the 'i' variable is the line number of the source file for the values coming in, and line 32 is the first line that triggers this error. Any ideas?

Replies are listed 'Best First'.
Re: Unknown Arithmetic Warning: Cannot determine source
by ysth (Canon) on Nov 04, 2008 at 05:12 UTC
      I don't know when it was fixed, but it's fixed in 5.8.8.
      >perl580\bin\perl -we"$cur[2]=20; $win[2]=100; $sec[2]=undef; if ($cur +[2] > $win[2]) {}" -e"elsif (0+$cur[2] > 0+$sec[2]) {}" Use of uninitialized value in addition (+) at -e line 1. >perl588\bin\perl -we"$cur[2]=20; $win[2]=100; $sec[2]=undef; if ($cur +[2] > $win[2]) {}" -e"elsif (0+$cur[2] > 0+$sec[2]) {}" Use of uninitialized value in addition (+) at -e line 2.
        I can't duplicate your result:
        ~$ perl5.8.8 -we'$cur[2]=20; $win[2]=100; $sec[2]=undef; if ($cur[2] > + $win[2]) {}' -e'elsif (0+$cur[2] > 0+$sec[2]) {}' Use of uninitialized value in addition (+) at -e line 1.
        And the same on 5.8.9-to-be.

        perl588\bin\perl -V?
Re: Unknown Arithmetic Warning: Cannot determine source
by ig (Vicar) on Nov 04, 2008 at 05:20 UTC

    You should probably look at $sec[2] used in an addition at line 140. The error message is telling you an empty string isn't numeric. You know $cur[2] is a number from the output of your print statement. How is $sec[2] being set?

Re: Unknown Arithmetic Warning: Cannot determine source
by johngg (Canon) on Nov 04, 2008 at 10:46 UTC
    Not solving your warning, but

    print "Begin: i=[$i], cur[2]=[",$cur[2],"], win[2]=[", $win[2], "]", "\n";

    You could save yourself some typing there because array elements can interpolate quite happily in double-quoted strings. I have also added escaped sigils so you can see them in the output.

    $ perl -e ' > @cur = (1, 2, 3); @win = (4, 5, 6); $i = 66; > print "Begin: \$i=[$i], \$cur[2]=[$cur[2]], \$win[2]=[$win[2]]\n";' Begin: $i=[66], $cur[2]=[3], $win[2]=[6] $

    I hope this is useful.

    Cheers,

    JohnGG