| Tie-Hash-Interpolate documentation | view source | Contained in the Tie-Hash-Interpolate distribution. |
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.
Hashes can either be tied using the tie builtin or by constructing one with
the new() method.
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' );
extrapolateThis 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)extrapolate linearly based on the two nearest points
constantkeep the nearest value constant rather than extrapolating
fatalthrow a fatal exception
undefreturn undef
one_keyThis 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)throw a fatal exception
constantall fetches return the one value that exists
undefreturn undef
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.
| Tie-Hash-Interpolate documentation | view source | Contained in the Tie-Hash-Interpolate distribution. |