ddoc has asked for the wisdom of the Perl Monks concerning the following question:
%hash{'key1'}{'key2'}='string'
I need to find key2 when string eq $1 from a previous regex. I would like to avoid another foreach because this hash can have over 1000 key1's and it is already nested inside 4 foreach loops.
That said, any solution is welcome, even with the foreach loops.
I have experimented a bit with grep but it seems to only work on arrays. I also had an idea to print the hash into a long string and then regex or grep it but it never led anywhere.
Update: my hash is 1:1 and I use this structure extensively and need to do this lookup just once. Using the reverse function did exactly what I needed. Thanks all.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: fast hash search
by davidrw (Prior) on May 20, 2006 at 00:41 UTC | |
|
Re: fast hash search
by GrandFather (Saint) on May 19, 2006 at 23:45 UTC | |
|
Re: fast hash search
by cdarke (Prior) on May 20, 2006 at 07:54 UTC | |
|
Re: fast hash search
by ioannis (Abbot) on May 20, 2006 at 00:06 UTC | |
|
Re: fast hash search
by John M. Dlugosz (Monsignor) on May 20, 2006 at 03:40 UTC |