Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Multiple Conditional Statements

by TJPride (Pilgrim)
on Sep 11, 2013 at 19:26 UTC ( #1053553=note: print w/replies, xml ) Need Help??


in reply to Multiple Conditional Statements

The best solution to finding dupes is almost always a hash.
use strict; use warnings; my ($RB1, $RB2, $WR1, $WR2, $TE1) = (1, 2, 3, 1, 4); { my %lookup; for ($RB1, $RB2, $WR1, $WR2, $TE1) { if ($lookup{$_}++) { print "Dupe $_\n"; last; } }}

Replies are listed 'Best First'.
Re^2: Multiple Conditional Statements
by dolmen (Beadle) on Sep 12, 2013 at 07:59 UTC
    This should work as the original values are numbers, but this is inefficient as the numeric values have to be stringified to be put as keys the hash. And the hash construction itself counts too.
      That only matters if you are working with literally millions of items, and the alternative is far worse. Constructing a hash is more efficient than, say, sorting a large list of items.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1053553]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2016-12-03 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (52 votes). Check out past polls.