Take a look at my Hash::Filler module. Perhaps it might be of help to you.

It allows you to define a set of "rules" to satisfy each lookup. And it caches the results.

Regards.

-lem

On Thursday, Jan 30, 2003, at 07:05 America/Caracas, Martyn J. Pearce wrote:

Authors,

I have a need for a new Tie module which I will satisfy today. I am surprised
that I can find no suitable implementation on CPAN; perhaps if I've missed a
contender, someone would be kind enough to point it out...

For the API of another module, I am required to pass in a hash of file
information of the form

local_filename => { URI => file_uri, MD5 => md5sum }

The information is coming in to me in another form, from several hashes, which
must be translated. This is fine; a little C<for> loop suffices. However,
the number of entries can get quite large --- up to 1 million; for which the
translation can take up an appreciable portion of an otherwise short-lived
program. Only a few of the entries are used in any one run. Performance is
proving an issue.

So, the solution which presents itself is a 'ProxyHash'. It takes a number of
hash references, and for each lookup requested, checks each reference in turn
until finding a match, at which point it returns the corresponding value. In
addition, each reference has an associated translator function to convert the
value prior to return.

This seems like such a simple application that I'm surprised I can't find one
on CPAN. If there is one, please point it out to me. If not, I propose to
create it today, and upload it as 'Tie::ProxyHash'. Comments?

Mx.


 --
#!/usr/bin/perl -w
use strict;
$_[$_]=0for 0..7;for$'(grep{s@^..@@}unpack"\1028"x28,join'',split//,
qq{=\37\34 \24(\31??\11\64:1\22\36/\24\2\12\4\b??\1\$\2\15\36}){$/=0
;grep{$_[$/++].=$_}split//,$';length$_[0]&@_&&print pack"\1028",$_
for@_;length$_[3]&@_&&grep{$_&=0}@_;}print"\n";

Reply via email to