in reply to Re^3: Check multiple array elements for a single condition
in thread Check multiple array elements for a single condition

Please explain what you mean by 'false positive'?

Thanks, Nick
  • Comment on Re^4: Check multiple array elements for a single condition

Replies are listed 'Best First'.
Re^5: Check multiple array elements for a single condition
by afoken (Chancellor) on Aug 25, 2016 at 18:47 UTC
    Please explain what you mean by 'false positive'?
    #!/usr/bin/perl use strict; use warnings; sub are_both_zero { my @array=@_; print "In the array (",join(', ',@array),"), "; if (!($array[0]+$array[1])) { print "both elements are zero.\n"; } else { print "at least one element is not zero.\n"; } } are_both_zero(3,-5); are_both_zero(3,0); are_both_zero(0,-5); are_both_zero(0,0); are_both_zero(3,-3);

    Output:

    In the array (3, -5), at least one element is not zero. In the array (3, 0), at least one element is not zero. In the array (0, -5), at least one element is not zero. In the array (0, 0), both elements are zero. In the array (3, -3), both elements are zero.

    See also https://en.wikipedia.org/wiki/False_positive.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Ah, OK. I got mislead. Great reply in that context. I don't know what the orignal poster requires if the array does hold negative values - I just read it if both are zero values.
      Nick