and 1 contributors

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

``````    ::          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`.

# METHOD

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

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.

parse(spec)

Accept number description and parse it. Return object itself.

range

Return number range list:

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

Return number sequence:

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