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.


In reply to Re: Search in Hash of Hash for the range of values by perlpie
in thread Search in Hash of Hash for the range of values by snape

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.