GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Interval2Prefix(3) User Contributed Perl Documentation Interval2Prefix(3)

Algorithm::Interval2Prefix - Generate prefixes from intervals

  use Algorithm::Interval2Prefix;

  my @prefixes = interval2prefix('33400','33599');
  print join(',', @prefixes);  # prints "334,335"

  my $regex = interval2regex('33400','33599');
  if ($n =~ /$regex/) { ... }

Taking an interval as input, this module will construct the smallest set of prefixes, such that all numbers in the interval will match exactly one of the prefixes, and no prefix will match a number not in the interval.

E.g. all numbers in the interval 39967000 to 39980999 would be matched by the following set of prefixes:

  39967
  39968
  39969
  3997
  39980

This type of conversion is particularly useful when working with telephony switching equipment, which usually determines call routing based on number prefixes rather than ranges.

Note that the numbers in the interval must be of the same length for the result to make sense.

The algorithm is much dependent on the number base, which defaults to 10. Other number bases can be specified explicitly.

An additional function is provided, that will generate a regular expression string matching only those numbers in the interval.

interval2prefix LO,HI,BASE
interval2prefix LO,HI
Yields an array of prefixes, covering the interval LO to HI, using number base BASE.

BASE is optional, and defaults to 10.

interval2regex LO,HI
Yields a regular expression string, which will match only those numbers in the interval.

This function assumes base 10.

Both interval2prefix() and interval2regex() are exported by default.

  • With interval2prefix(), the endpoints of the interval must be the same length (same number of digits in the particular number base) for the results to make any sense.
  • interval2regex() only does base 10.

Please report issues via CPAN RT:

  http://rt.cpan.org/NoAuth/Bugs.html?Dist=Algorithm-Interval2Prefix

or by sending mail to

  bug-Algorithm-Interval2Prefix@rt.cpan.org

Lars Thegler <lars@thegler.dk>

Copyright (c) 2003 Lars Thegler. All rights reserved.

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

2003-12-02 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.