Gretings Monks!

I am trying to search a Hash of Hashes of Arrays (%HoHoA), copying all matches to a new Hash of Arrays of Hashes of Arrays (%HoAoHoA). Something like the following:

$interval = <STDIN>; #a number, typically on the order of 500 %HoHoA = ( 'I' => { $a => [4,10,200,6000,7000,7100], $b => [75,350,5900,6402,7110], $c => [0,95,5990,6450] }, 'II' => { $a => [lots of numbers], $b => [lots of numbers], $c => [lots of numbers] }, 'III' => { $a => [lots of numbers], $b => [lots of numbers], $c => [lots of numbers] } );
I'd then have some nifty search routine (which is where I'm asking for help) that would for each key (I, II, III, etc), look at all the array elements for all it's sub-keys (a, b, c, etc), and from those, find all the groups that are within$interval of each other, and return these still in their respective organizational structure. so, thinking codally here,
for $RomanNumeral (keys %HoHoA) { # For each key RomanNumeral for $letter (keys sort {$a <=> $b } %{$HoHoA{$RomanNumeral}} { # The sort will work here, because in this case, the $a, $b, etc are + indices # For each lettered array in that key $i = 0; for ($i < length($HoHoA{$RomanNumeral}{$letter})-1) { $lowerlimit = $HoHoA{$RomanNumeral}{$letter}[$i]; $upperlimit = $interval + $lowerlimit; #Set a lower limit and an upper limit to the range of numbers we + are looking for if ($element >= $lowerlimit && $element <= $upperlimit) { save $element's value to a new array, keyed by both $RomanN +umeral and $letter $element here corresponds to all values in the hash %{HoHoA{ +$RomanNumeral}}, regardless of their $letter key. } $i++; } }
The desired output would then be a Hash whose keys are $RomanNumerals, and whose values would be Arrays. Each element of those arrays would correspond to a set of matches to all the numbers within $interval of each other, starting from the lowest element in the %{$HoHoA{$RomanNumeral}} hash, regardless of it's array of origin. The format of the elements of those arrays however, would be hashes, where the elements of the match would be stored as arrays which are the values corresponding to the $letter keys.

Given the first roman numeral in the top block of code I included, the matches would be:

$interval = 500; %HoAoHoA = ( 'I' => [ {$a => [4,10,200], $b => [75,350], $c => [0, 95]}, {$a => [6000], $b =[5900], $c =>[5990]}, {$a => [], $b =[6402], $c =>[6450]}, {$a => [7000,7100], $b =[7110], $c =>[]},
I hope that makes sense to anyone other than me....

I'd appreciate any help anyone can offer me in figuring out the search mechanism in the middle block. I am sure that I could figure it out given enough time and Google searches, but if anyone can help me cut through it more quickly, I'd be greatly obliged.

Thanks!
Matt


In reply to taking a subset of HoHoA, retaining relative structure? by mdunnbass

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.