http://www.perlmonks.org?node_id=1053462


in reply to Multiple Conditional Statements

You could use an anonymous hash:

( $RB1, $RB2, $WR1, $WR2, $TE1 ) = map int( rand 10 ), 1 .. 5;; print $RB1, $RB2, $WR1, $WR2, $TE1;; 3 5 5 8 7 if( keys %{ { map{ $_,$_ } $RB1, $RB2, $WR1, $WR2, $TE1 } } == 5 ) { say 'all different' } else { say 'some same' };; some same ( $RB1, $RB2, $WR1, $WR2, $TE1 ) = map int( rand 10 ), 1 .. 5;; print $RB1, $RB2, $WR1, $WR2, $TE1;; 1 8 6 7 5 if( keys %{ { map{ $_,$_ } $RB1, $RB2, $WR1, $WR2, $TE1 } } == 5 ) { say 'all different' } else { say 'some same' };; all different

But be wary of what you mean by "different" if these can be floating point values.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Multiple Conditional Statements
by vsespb (Chaplain) on Sep 11, 2013 at 11:14 UTC
    There can be problem with string vs numeric comparison:
    use v5.10; ( $RB1, $RB2, $WR1, $WR2, $TE1 ) = (1,2, 3, "05", 5); if( keys %{ { map{ $_,$_ } $RB1, $RB2, $WR1, $WR2, $TE1 } } == 5 ) { say 'all different'; } else { say 'some same' };; prints "all different"

      For strictly numeric comparison add 0+:

      if( keys %{ { map{ 0+$_,$_ } $RB1, $RB2, $WR1, $WR2, $TE1 } } == 5 ) { + say 'all different' } else { say 'some same' };;

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Yes, that would work.

      Indeed.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.