I originally began with this:
###
$first = param('original');
$second = param('second');
%arr = (
'yellow' => 'blue',
'red' => 'green'
);
if ($arr{$first} eq $second || $arr{$second} eq $first) { $filter = 1; }
###
So if $first is "yellow" and $second is "blue", OR if $first is "blue" and $second is "yellow", then $filter will be set.
In practice, I have about 70 keys. But over time, I'm having to deal with duplicate possibilities. So in theory, I wrote this:
###
%arr = (
'yellow' => 'blue',
'yellow' => 'green',
'yellow' => 'red',
'red' => 'green'
);
if ($arr{$first} eq $second || $arr{$second} eq $first) { $filter = 1; }
###
But of course, this doesn't work because $arr{'yellow'} now equals "red", so "blue" or "green" would no longer match. And I can't just reverse it, because the values duplicate, too ("green" is a value for both "yellow" and "red").
I believe that I can fix it with a hash of arrays, so something like:
###
%arr = (
yellow => {
'blue' => 1,
'green' => 1,
'red' => 1
},
red => {
'green' => 1
}
);
if ($arr{$first}{$second} || $arr{$second}{$first}) { $filter = 1; }
###
Before I implement this, (1) do you guys see any problem with my coding, and (2) can you suggest a better / more readable way to do what I'm trying to do?