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

Dave Cross dave at dave.org.uk
Wed Mar 12 15:15:46 GMT 2008

Quoting David Cantrell <david at cantrell.org.uk>:

> 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?

Tie::RegexpHash perhaps.


Then you only need to write regexes to match all ints, all floats, etc.


More information about the london.pm mailing list