Getopt::EX::Numbers - module to handle number parameters
use Getopt::EX::Numbers;
my $obj = Getopt::EX::Numbers->new(max => 100);
$obj->parse("start:end:step:length"); $obj->range;
$obj->parse("start:end:step:length")->sequence;
Getopt::EX::Numbers->new->parse("1:10:2")->sequence;
Getopt::EX::Numbers->new(start=>1,end=>10,step=>2)->sequence;
Number format is composed by four elements: start, end, step and length. All elements are optional.
start
end
step
length
1 1 1:3 1,2,3 1:20:5 1, 6, 11, 16 1:20:5:3 1,2,3, 6,7,8, 11,12,13, 16,17,18
When start is omitted, minimum value is used, which is zero by default. If the object is initialized with max value, end element can be omitted.
max
:: all ::2 even numbers 1::2 odd numbers
If start and end number is negative, they are subtracted from the maximum number. If the end number is prefixed by plus (`+') sign, it is summed to start number. Next examples produce top and last 10 numbers.
:+9 top 10 numbers -9: last 10 numbers
{n} operator can be used to repeat preceeding expression. 3{5} means 3,3,3,3,3. 2:6:2{3} means 2,4,6,2,4,6,2,4,6.
{n}
3{5}
3,3,3,3,3
2:6:2{3}
2,4,6,2,4,6,2,4,6
Create object with optional parameter min and max.
Other parameters (start, end, step, length) also can be specified with new method. This is equivalent to use parse method.
Accept number description and parse it. Return object itself.
Return number range list:
( [ n0, m0 ], [ n1, m1 ], ... )
Return number sequence:
( n0 .. m0, n1 .. m1, ... )
To install Getopt::EX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Getopt::EX
CPAN shell
perl -MCPAN -e shell install Getopt::EX
For more information on module installation, please visit the detailed CPAN module installation guide.