One of the most important things to learn when starting to program is precision in your specification of the problem. You must thoroughly understand what you want to program, because the computer is stupid enough to do exactly what you ask.
Now, to help refine your requirements, we need to ask more questions:
Can you have multiple output items in the same group?
What if the first values are not within 10 but the second ones are, what do we want to do?
The main point of the questions is to make certain you are perfectly clear on what should happen for any inputs.
If you can only have one output line for each group, then a hash is a really good way to organize the data. If you can have more than one output line, then you need to get more creative. A hash can only have one value per key, but that value could be a reference to an array.
For example, the data structure for the initial input could be:
my %data = ( 'group1' => [ [32,48], [31,49], [57,91], [52,89] ], 'group3' => [ [10,19] ], 'group4' => [ [23,77] ], );
In this case, each group (key) has an array as a value, and each of those arrays has references to a 2 item list that has the min and max values.
Although not really difficult, this structure might take a little study to become comfortable.
In reply to Re: compare values within a hash
by gwadej
in thread compare values within a hash
by rookierabbit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |