mdunnbass has asked for the wisdom of the Perl Monks concerning the following question:
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:
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,$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] } );
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.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++; } }
Given the first roman numeral in the top block of code I included, the matches would be:
I hope that makes sense to anyone other than me....$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'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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: taking a subset of HoHoA, retaining relative structure?
by jdporter (Paladin) on Oct 18, 2006 at 20:33 UTC | |
by mdunnbass (Monk) on Oct 18, 2006 at 20:40 UTC | |
|
Re: taking a subset of HoHoA, retaining relative structure?
by Not_a_Number (Prior) on Oct 19, 2006 at 14:08 UTC | |
by mdunnbass (Monk) on Oct 19, 2006 at 20:07 UTC |