rookierabbit has asked for the wisdom of the Perl Monks concerning the following question:
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.
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: compare values within a hash
by JavaFan (Canon) on Oct 27, 2008 at 16:57 UTC | |
by rookierabbit (Initiate) on Oct 27, 2008 at 17:32 UTC | |
by gwadej (Chaplain) on Oct 27, 2008 at 18:55 UTC | |
|
Re: compare values within a hash
by gwadej (Chaplain) on Oct 27, 2008 at 17:21 UTC | |
by rookierabbit (Initiate) on Oct 27, 2008 at 17:40 UTC | |
by gwadej (Chaplain) on Oct 27, 2008 at 18:52 UTC | |
by ig (Vicar) on Oct 27, 2008 at 19:44 UTC | |
|
Re: compare values within a hash
by GrandFather (Saint) on Oct 27, 2008 at 22:41 UTC | |
|
Re: compare values within a hash
by toolic (Bishop) on Oct 27, 2008 at 17:12 UTC |