in reply to Complex Hash

Look into the Memoize function, which can remember the results of prior queries to speed it up. First, break out the lookup into a separate function:
sub lookup { die unless wantarray; # call me in list context only my $item = shift; return values %{$EMail{$item}} if exists $EMail{$item}; # category n +ame for my $cat (keys %EMail) { return $EMail{$cat}{$item} if exists $EMail{$cat}{$item}; # single + name } return; # not found } sub GetEmailFor { my @results = map { lookup($_) } @_; return join ",", @results; }
This should be equivalent code (and quite faster, I might add {grin}). Now, let's speed it up further:
use Memoize; memoize('lookup'); sub I_have_changed_EMail { unmemoize('lookup'); memoize('lookup'); }
and be sure to call I_have_changed_EMail any time you change your dataset (none at all if you "set it and forget it", as you indicate already).

There. Speed without too much work.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: Re: Complex Hash
by Adam (Vicar) on Sep 06, 2000 at 04:23 UTC
    That would work well if GetEMailFor() was being called lots of times with the same query, but it isn't. Its being called several times with almost every query being different.
      Please relook. I'm memoizing the underlying individual items. Not the combination of what's being called to GetEMailFor.
      "Please read for comprehension!" -- PurlGurl {grin}

      -- Randal L. Schwartz, Perl hacker

        Yes, but the combination is not what matters. Its almost a red herring. In fact, I'm not even using that ability (yet), I merely provided for it in case I needed it. (and if I find that I don't I will probably take it out.)

        What is bothering me is that I have to check every key until I find the match, starting from some arbitrary point. (Arbitrary to me, not Perl) I lose the true advantage of an associative array... the hashing algorithm.

        By the way, your quote:
        "Please read for comprehension!" -- PurlGurl {grin}
        Implies that I didn't comprehend your suggestion. I am offended at your arrogance.