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

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.)


Comment on Re: Multiple Conditional Statements
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-09-21 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls