Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Multiple Conditional Statements

by sundialsvc4 (Abbot)
on Sep 11, 2013 at 15:57 UTC ( #1053516=note: print w/replies, xml ) Need Help??

in reply to Multiple Conditional Statements

Anytime I see repeating-variable names like $RBn, I immediately think that $RB should instead be, say, a list with n elements in it.   And in this case, that maybe the root variable should be a hash with keys such as 'RB', 'TE', 'WR'.

When looking for dupes, and especially if the values are scalar or string, a hash can come in handy:   you jump-out as soon as anything exists(), viz ... for illustration only ...

my $dupes = {}; for my $k (qw/RB TE WR/) { for my $n (qw/1 2 3 4 5/) { $n = $my_data->{$k}{$v}; return 'DUPLICATE FOUND' if exists($dupes->{$n}); $dupes->{$n} = 1; // DON'T CARE ANY VALUE WILL DO } } return 'NO DUPLICATES';

This example illustrates the use of a hash ($my_data) to store the values, and of a hash ($dupes) to find duplicates.   The technique would not work so-good if the values being sought were floating point.)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-03-22 04:58 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (272 votes). Check out past polls.