Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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]
[Corion]: Hi marto!
choroba greets
[choroba]: .org and .com not working for me today, only .net
Eily is connected on .org

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2017-10-23 09:14 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (277 votes). Check out past polls.