Number::Range - Perl extension defining ranges of numbers and testing later if a number is in it


  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";


Number::Range will take a description of range(s), and then allow you to test later on if a number falls within the range(s).


The format used for range is pretty straight forward. To separate sections of ranges it uses a , or whitespace. To create the range, it uses .. to do this, much like Perl's own binary .. range operator in list context.


$range = Number::Range->new("10..20","25..30");

Creates the range object. It will accept any number of ranges as its input.


This will also take any number of ranges as input and add them to the existing range.


This will also take any number of ranges as input and delete them from the existing range.

$range->inrange("26"); my @results = $range->inrange("27","200");

This will take one or more numbers and check if each of them exists in the range. If passed a list, and in array context, it will return a list of 0's or 1's, depending if that one was true or false in the list position. If in scalar context, it will return a single 1 if all are true, or a single 0 if one of them failed.

$format = $range->range; @numbers = $range->range;

This will output either a list of all the numbers in the range, if in list context, or it will output a range format suitable to be used again for a new range.


None by default.


Larry Shatzer, Jr., <>


Copyright (C) 2004 by Larry Shatzer, Jr.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 198:

'=item' outside of any '=over'

Around line 223:

You forgot a '=back' before '=head2'