Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Check multiple array elements for a single condition

by Linicks (Scribe)
on Aug 25, 2016 at 18:40 UTC ( [id://1170473]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1170473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found