in reply to Search in Hash of Hash for the range of values

First off, I think you may have a typo. You're referencing a $col2_ variable (note the trailing underscore) that I don't think you meant to. I'm also guessing you wanted dollar signs in the right hand side too. Did you mean something like this?

$hash{$col1}{$col2 . '_' . $col3} = "$col4\t$col5"

Second, I don't know the context here, but it sounds like this sort of comparison and filtering would have been easier to do back before things had been put in the HoH.

On the assumption that this isn't an option, how about the following?

for my $c1 (keys %hash) { for my $c2_c3 (keys %{$hash{$c1}}) { my ($c2, $c3) = split('_', $c2_c3); if ( () # $c2 is ok && () # $c3 is ok ) { # do stuff for good data } else { # do stuff for bad data } } }

You'll have to fill in your range tests and actions to take for good/bad data.

Replies are listed 'Best First'.
Re^2: Search in Hash of Hash for the range of values
by snape (Pilgrim) on Sep 02, 2010 at 08:03 UTC

    Thanks a lot. It worked for me.

Re^2: Search in Hash of Hash for the range of values
by aquarium (Curate) on Sep 02, 2010 at 01:03 UTC
    following on from that..but going out on a limb: i think you're trying to create/process some kind of a bookmark in text, which has starting and ending positions in text.
    what you're doing with combining two values into one hash key is probably not a good idea..as it's just made your job a whole lot harder. a HoHoH works better than Ho{H.H}
    also, if my assumption about the problem is in the ballpark, it's probably better to store as starting position and ending position offset (length); rather than starting position and ending position. you can always quickly calculate the ending position if absolutely necessary at a point in time, but easier to handle the thing (i think) with a start pos + length. your range tests then become rather simple.
    the hardest line to type correctly is: stty erase ^H