NAME

Getopt::EX::Numbers - module to handle number parameters

SYNOPSIS

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;

FORMAT

Number format is composed of four elements: start, end, step and length. All elements are optional.

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, the minimum value is used, which is zero by default. If the object is initialized with a max value, the end element can be omitted.

::		all
::2		even numbers
1::2	odd numbers

If the start and end numbers are negative, they are subtracted from the maximum number. If the end number is prefixed by a plus (`+') sign, it is added to the start number. The next examples produce the top and last 10 numbers.

:+9		top 10 numbers
-9:		last 10 numbers

The {n} operator can be used to repeat the preceding expression. 3{5} means 3,3,3,3,3. 2:6:2{3} means 2,4,6,2,4,6,2,4,6.

METHOD

new ( [ min => n ] , [ max => m ] ... )

Create an object with optional parameters min and max.

Other parameters (start, end, step, length) can also be specified with the new method. This is equivalent to using the parse method.

parse(spec)

Accept a number description and parse it. Returns the object itself.

range

Returns a number range list:

( [ n0, m0 ], [ n1, m1 ], ... )
sequence

Return number sequence:

( n0 .. m0, n1 .. m1, ... )