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

Comment on Re: Multiple Conditional Statements
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2015-11-27 08:24 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (722 votes), past polls