in reply to Complex Hash
This should be equivalent code (and quite faster, I might add {grin}). Now, let's speed it up further: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; }
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).use Memoize; memoize('lookup'); sub I_have_changed_EMail { unmemoize('lookup'); memoize('lookup'); }
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 | |
by merlyn (Sage) on Sep 06, 2000 at 04:25 UTC | |
by Adam (Vicar) on Sep 06, 2000 at 04:29 UTC | |
by merlyn (Sage) on Sep 06, 2000 at 04:30 UTC | |
by Adam (Vicar) on Sep 06, 2000 at 04:39 UTC | |
|