1Number::Range(3)      User Contributed Perl Documentation     Number::Range(3)
2
3
4

NAME

6       Number::Range - Perl extension defining ranges of numbers and testing
7       if a number is found in the range. You can also add and delete from
8       this range.
9

SYNOPSIS

11         use Number::Range;
12
13         my $range = Number::Range->new("-10..10,12,100..120");
14         if ($range->inrange("13")) {
15           print "In range\n";
16         } else {
17           print "Not in range\n";
18         }
19         $range->addrange("200..300");
20         $range->delrange("250..255");
21         my $format = $range->range;
22         # $format will be '-10..10,12,100..120,200..249,256..300'
23

DESCRIPTION

25       Number::Range will take a description of a range, and then allow you to
26       test on if a number falls within the range. You can also add and delete
27       from the range.
28
29   RANGE FORMAT
30       The format used for range is pretty straight forward. To separate
31       sections of ranges it uses a "," or whitespace. To create the range, it
32       uses ".." to do this, much like Perl's own binary ".." range operator
33       in list context.
34
35   METHODS
36       new
37             $range = Number::Range->new("10..20","25..30","100");
38
39           Creates the range object. It will accept any number of ranges as
40           its input.
41
42       addrange
43             $range->addrange("22");
44
45           This will also take any number of ranges as input and add them to
46           the existing range.
47
48       delrange
49             $range->delrange("10");
50
51           This will also take any number of ranges as input and delete them
52           from the existing range.
53
54       inrange
55             $range->inrange("26"); my @results = $range->inrange("27","200");
56
57           This will take one or more numbers and check if each of them exists
58           in the range. If passed a list, and in array context, it will
59           return a list of 0's or 1's, depending if that one was true or
60           false in the list position. If in scalar context, it will return a
61           single 1 if all are true, or a single 0 if one of them failed.
62
63       range
64             $format = $range->range; @numbers = $range->range;
65
66           Depending on context this will return either an array of all the
67           numbers found in the range, for list context. For scalar context it
68           will return a range string.
69
70       size
71             $size = $range->size;
72
73           This will return the total number of entries in the range.
74
75       rangeList
76             @rangeList = $range->rangeList;
77
78           Returns the range as an array list where each element in the list
79           is an array representing the start and stop points of a range.
80           Single element ranges are returned as single element arrays with
81           only on indice.
82
83           [
84             [10,20],
85             [25,30],
86             [100] ]
87
88   EXPORT
89       None by default.
90

SEE ALSO

92       Number::Tolerant, Tie::RangeHash, and Array::IntSpan for similar
93       modules.
94

AUTHOR

96       Larry Shatzer, Jr., <larrysh@cpan.org>
97
99       Copyright (C) 2004-14 by Larry Shatzer, Jr.
100
101       This library is free software; you can redistribute it and/or modify it
102       under the same terms as Perl itself.
103
104
105
106perl v5.36.0                      2022-07-22                  Number::Range(3)
Impressum