Number::Range(3pm)
π Number::Range π
okay bestie, so Number::Range is this Perl extension that lets you define ranges of numbers and then test whether a number is chillin' inside that range. and like β plot twist β you can also add to it and delete from it. the range is literally alive. it's giving β¨main characterβ¨. no cap.
β¨ SYNOPSIS β¨
use Number::Range;
my $range = Number::Range->new("-10..10,12,100..120");
if ($range->inrange("13")) {
print "In range\n";
} else {
print "Not in range\n";
}
$range->addrange("200..300");
$range->delrange("250..255");
my $format = $range->range;
# $format will be '-10..10,12,100..120,200..249,256..300'
πΈ DESCRIPTION πΈ
so Number::Range takes a description of a range, and then lets you test whether a number falls within the range. you can also add and delete from the range. it's the whole package, fr fr. π«Ά
π RANGE FORMAT π
the format for a range is pretty straight forward, bestie. to separate sections of ranges it uses a "," or whitespace. and to actually create the range, it uses ".." to do it β much like Perl's own binary .. range operator in list context. iykyk. π
π METHODS π
new
$range = Number::Range->new("10..20","25..30","100");
creates the range object, obviously. it will accept any number of ranges as its input. as many as you want. go off. π
addrange
$range->addrange("22");
this one also takes any number of ranges as input and adds them to the existing range. growing the range. expanding the empire. β¨
delrange
$range->delrange("10");
yep, same energy β this also takes any number of ranges as input and deletes them from the existing range. bye bestie, you're not in the range anymore π
inrange
$range->inrange("26"); my @results = $range->inrange("27","200");
this takes one or more numbers and checks if each of them exists in the range.
- if you pass it a list, and you're in array context, it returns a list of
0's or1's β depending on whether that one was true or false in the list position. - if you're in scalar context, it returns a single
1if all of them are true, or a single0if one of them failed.
it's giving all-or-nothing in scalar mode. periodt.
range
$format = $range->range; @numbers = $range->range;
context-dependent queen π β depending on context this returns either:
- in list context, an array of all the numbers found in the range.
- in scalar context, a range string.
size
$size = $range->size;
this returns the total number of entries in the range. the headcount. the vibe check result. π¦
rangeList
@rangeList = $range->rangeList;
returns the range as an array list, where each element in the list is an array representing the start and stop points of a range. single element ranges are returned as single element arrays with only on indice.
[
[10,20],
[25,30],
[100] ]
look at those little nested arrays. iconic. π
π EXPORT π
None by default. nope. nada. you get nothing unless you ask. π
π SEE ALSO π
Number::Tolerant, Tie::RangeHash, and Array::IntSpan for similar modules. if Number::Range isn't your vibe, these are the other besties in the group chat. π«Ά
π«Ά AUTHOR π«Ά
Larry Shatzer, Jr., <larrysh@cpan.org> β the legend, the icon, the moment. β¨
π COPYRIGHT AND LICENSE π
Copyright (C) 2004-14 by Larry Shatzer, Jr. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page bestie!! πΈ this is Number::Range, documented in perl v5.34.0, dated 2022-06-16. mwah, go slay your ranges π ππ
π¦ where this page comes from
- debian bookworm: libnumber-range-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libnumber-range-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnumber-range-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnumber-range-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnumber-range-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms