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

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.

  • Comment on Re: Search in Hash of Hash for the range of values

Replies are listed 'Best First'.
Re^2: Search in Hash of Hash for the range of values
by marinersk (Priest) on Sep 02, 2010 at 05:46 UTC

    Wow, it's been awhile since I've been downvoted.

    Not that my feelings are hurt, but wondering what in my post elicited the reaction. LOL. Can't improve if I don't know what's wrong.

    Ah, well, such is the nature of a drive-by shooting. :: giggle ::

      Yeah, I've been seeing that happening today in other threads. To me and also to other folks. I guess somebody just is having a bad day for some unknown reason. I don't see any problem with your post and I retaliated with an up vote! You are right, there isn't a tricky way to do everything and sometimes even there is, sometimes it would be so obscure looking that its probably not a good idea to do it!