Tie::Hash::Interpolate - tied mathematical interpolation/extrapolation
Version 0.07
use Tie::Hash::Interpolate; ## use tie interface tie my %lut, 'Tie::Hash::Interpolate', extrapolate => 'linear'; $lut{3} = 4; $lut{5} = 6; print $lut{4}; ## prints 5 print $lut{6.5}; ## prints 7.5 ## or constructor interface my $lut = Tie::Hash::Interpolate->new( extrapolate => 'linear' ); $lut->{3} = 4; $lut->{5} = 6; print $lut->{4}; ## prints 5 print $lut->{6.5}; ## prints 7.5
Tie::Hash::Interpolate provides a mechanism for using a hash as a lookup table for interpolated and extrapolated values.
Tie::Hash::Interpolate
Hashes can either be tied using the tie builtin or by constructing one with the new() method.
tie
new()
After your hash is tied (NOTE: key-value pairs added prior to the tie will be ignored), insert your known key-value pairs. If you then fetch a key that does not exist, an interpolation or extrapolation will be performed as necessary. If you fetch a key that does exist, the value stored for that key will be returned.
Options can be passed to tie after the Tie::Hash::Interpolate name is given, or directly to new() as key-value pairs.
tie my %lut, 'Tie::Hash::Interpolate', extrapolate => 'fatal'; ## or my $lut = Tie::Hash::Interpolate->new( one_key => 'constant' );
extrapolate
This option controls the behavior of the tied hash when a key is requested outside the range of known keys. Valid extrapolate values include:
linear (default)
linear
extrapolate linearly based on the two nearest points
constant
keep the nearest value constant rather than extrapolating
fatal
throw a fatal exception
undef
return undef
one_key
This option controls the behavior of the tied hash when a key is requested and only one key exists in the hash. Valid one_key values include:
fatal (default)
all fetches return the one value that exists
Daniel B. Boorstein, <danboo@cpan.org>
Copyright 2004 by Daniel B. Boorstein
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Tie::Hash::Interpolate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Hash::Interpolate
CPAN shell
perl -MCPAN -e shell install Tie::Hash::Interpolate
For more information on module installation, please visit the detailed CPAN module installation guide.