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.

G. Wade

In reply to Re: compare values within a hash by gwadej
in thread compare values within a hash by rookierabbit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.