Tie::NumRange - Keeps a number within a range of values.
use Tie::NumRange; tie my($chr), Tie::NumRange => ( 100, # initial 0, # min 255, # max ); $chr *= 3; # $chr is 255 $chr = -5; # $chr is 0 tie my($positive), Tie::NumRange => ( 1, 1, undef ); $positive = 2**16; # ok $positive = 0; # $pos is 1 tie my($wrap), Tie::NumRange::Wrap => ( 0, # initial 0, # min 10, # max ); while ($wrap < 10) { # 0, 3, 6, 9, 2, 5, 8, 1, 4, 7 $wrap += 3; }
This module institutes a range of values for a number. The lower and upper bounds can be unlimited by passing undef in their place.
undef
Tie::NumRange
tie $number, Tie::NumRange => ($init, $min, $max);
If $min is undef, the number has no lower bound. Likewise for $max.
$min
$max
Tie::NumRange::Wrap
tie $number, Tie::NumRange::Wrap => ($init, $min, $max);
Neither range can be undef. The value will wrap around when it goes outside the stated bounds.
Jeff "japhy" Pinyan CPAN ID: PINYAN japhy@pobox.com http://www.pobox.com/~japhy/
To install Tie::NumRange, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::NumRange
CPAN shell
perl -MCPAN -e shell install Tie::NumRange
For more information on module installation, please visit the detailed CPAN module installation guide.