Sigh! I come to you, Monks, out of frustration, desperation, etc. I am fairly new to Perl and programming. The hardest part isn't learning the language, rather understanding approaches. With that said, here is my problem. I have a file of lines in an array

group1 32 48 group1 31 49 group1 57 91 group1 52 89 group3 10 19 group4 23 77

I would like to compare each element with all the rest. If the groups are the same, I would like to look at the first numerical value. If they are within 10 of each other, I would like to take the lesser value and then look at the second number. If they are within 10, I would like to take the greater value.

It seems the best thing to do is put them into a hash of hashes and compare these. Is this smart/possible?

I read the many archived posts and think I have an idea how to do this, but not really an understanding. Also, if two or more lines are "collapsed" into one, I want to make sure to eliminate the old lines so that I have one representative that encompasses the largest range.


i.e.
group1 31 49 group1 52 91 group3 10 19 group4 23 77

Does this make sense? I know I excluded any code. I am looking more for theory right now than code as I would like to try to learn it while writing it. Like I said, it seems to be programming theory that I am having real troubles with. Thanks in advance!


In reply to 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.