NAME
NumberUtil - Perl module to produce number list from spec
SYNOPSIS
range_list(spec => "start:end:step:length", max => 100);
DESCRIPTION
- range_list ( spec => "spec", [ min => n, max => m ])
-
Accept number spec and maximum value, and return number range list:
( [ n0, m0 ], [ n1, m1 ], ... )
For example,
10:20
means numbers from 10 to 20, and produces the result ( [ 10, 20 ] ).Third number means step count, and
10:20:2
produces even numbers from line 10 to 20:
( [ 10, 10 ], [ 12, 12 ] .. [ 20, 20 ] )
Any of them can be omitted. Next specs means all, odd and even numbers.
:: all ::2 odd numbers 2::2 even 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
If the forth parameter is given, it describes how many numbers are included in that step cycle. For example,
::10:3
produces:
( [ 0, 2 ], [ 10, 12 ], [ 20, 22 ], ... )
Minimum number is zero by default, and can be set by `min' parameter. Maximum number is optional but required in some operations.