Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Multiple Conditional Statements

by vsespb (Hermit)
on Sep 11, 2013 at 11:25 UTC ( #1053470=note: print w/ replies, xml ) Need Help??


in reply to Re: Multiple Conditional Statements
in thread Multiple Conditional Statements

Same problem with your example and with uniq() - string vs numeric comparison. Can be worked around by numifying data:

use strict; use warnings; use Test::More; sub all_different { my %seen; for ( @_ ) { return 0 if $seen{$_}++; } #-- duplicate found return 1; } # e.g. if ( all_different($RB1, $RB2, $WR1, $WR2, $TE1) ) { ... is( all_different( 1,2,3,4,5 ), 1 , "all different"); is( all_different( 1,2,3,"05",5 ), 0 , "some duplicates with different + string"); is( all_different( map { $_+0 } 1,2,3,"05",5 ), 0 , "some duplicates w +ith different strings numified"); is( all_different( 1,1,3,4,5 ), 0 , "some duplicates"); is( all_different(), 1 , "empty paramlist"); done_testing;
result:
ok 1 - all different not ok 2 - some duplicates with different string # Failed test 'some duplicates with different string' # at 3.pl line 17. # got: '1' # expected: '0' ok 3 - some duplicates with different strings numified ok 4 - some duplicates ok 5 - empty paramlist 1..5


Comment on Re^2: Multiple Conditional Statements
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-07-10 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (216 votes), past polls