A less approximate version of Tie::Hash::Approx

Zbigniew Lukasiak zzbbyy at gmail.com
Thu Mar 13 07:37:12 GMT 2008

On Wed, Mar 12, 2008 at 3:50 PM, David Cantrell <david at cantrell.org.uk> wrote:
> I need a module that will let me tie a hash so that if I try to FETCH a
>  value for a key that exists, then it'll return the appropriate value,
>  but will also let me fetch values for keys that match certain rules.
>  eg so that ...
>     tie %hash, ....
>     $hash{Hobbes} = 'feline';
>     $hash{Lassie} = 'canine';
>     # set up some magic here
>     print "Hobbes is a $hash{Hobbes}\n";
>     print "Lassie is a $hash{Lassie}\n";
>     print "42 is an $hash{42}\n";        # 42 gets caught by some magic
>     print "3.5 is a $hash{3.5}\n";       # 3.5 matches some other magic
>     print "Skippy is a $hash{Skippy}\n"; # Skippy doesn't exist
>  will print:
>     Hobbes is a feline
>     Lassie is a canine
>     42 is an integer
>     3.5 is a floating point number
>     Skippy is a Use of uninitialized value in concatenation
>  without me having to define values for all real numbers, which would be
>  the sort of task I might set a work-experience kid if I don't like their
>  haircut.
>  Can anyone point me at something on the CPAN, or am I going to have to
>  write this myself?

Maybe not very helpful - but I think it is hard to see where you would
like to stop your generalisation before getting a universal function
call instead of a hash lookup.

>  --
>  David Cantrell | top google result for "topless karaoke murders"
>  Feature: an incorrectly implemented bug

Zbigniew Lukasiak

More information about the london.pm mailing list