Dear snape,

I suspect your problem is that you are trying to find an easy-as-Perl way to do something that has no Perl shortcuts.

It comes up from time to time here; someone goes through the gyrations of learning to use HoH, which gives them the abililty to find data in complex structures with extremely lightweight code -- precisely what Hashes are designed to do.

Then they (or the people who inherit their code) suddenly discover that, lo and behold, sometimes you have to search the keys, too.

And they show up at the Monastery Gates looking for that magic shortcut way to get it done, since Perl "always" has those, only to discover that this is NOT what hashes were designed to do.

So, unfortunately, you're just going to have to search through the keys the old fashioned way. Anathema to Perl, perhaps, but, yes, you'll have to write five lines of Perl instead of one. :-)

By the way, there are technically at least two "old fashioned" ways to do this, not including going to external tools like SQL as admirably noted above.

One is as shown above, the looped and/or recursive search through the key tree.

The other is to rewrite the data storage portion of the script; at the same time it writes data to the hash, it then immediately also writes the key(s) to a reverse-lookup list (hash or array, depending on the need). Then you can search for your keys in the reverse-lookup list, often using those lovely Perl shortcuts we all get so accustomed to having at our fingertips.

Either way, sorry to say, this is not a new problem, and there is no silver bullet. You have to actually slog through the keys or change the way the data is stored in the first place.


In reply to Re: Search in Hash of Hash for the range of values by marinersk
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.