develooper Front page | perl.module-authors | Postings from November 2003

New module Algorithm::Interval2Prefix

Thread Next
From:
Lars Thegler
Date:
November 30, 2003 08:17
Subject:
New module Algorithm::Interval2Prefix
Message ID:
017901c3b75d$685b95e0$6400000a@marvin
Hi all,

I've written a small module, encapsulating an algorithm that can generate a
set of 'prefixes' (patterns that match the beginning of a numeric string)
from an 'interval' (range) of integers. This is a problem often occurring
working with telephony switching equipment or IP address subnetting.

I've trawled CPAN to locate prior work with similar functionality, but to no
avail.

The POD is attatched below, and the module distfile can be fetched from

http://lars.thegler.dk/perl/Algorithm-Interval2Prefix-0.01.tar.gz

Question: Am I reinventing something here?

Question: Is the namespace appropriate?

Comments on code, style etc are welcome.


/Lars


--cut--
NAME
    Algorithm::Interval2Prefix - Generate prefixes from intervals

SYNOPSIS
      use Algorithm::Interval2Prefix;
      my @prefixes = interval2prefix('33400','33599');

      print join(',', @prefixes);  # prints "334,335"

DESCRIPTION
    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.

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

FUNCTIONS
  "interval2prefix()"
      my @p = interval2prefix($lo, $hi);
       or
      my @q = interval2prefix($lo, $hi, $base);

    Yields an array of prefixes, covering the interval $lo to $hi, using
    number base $base.

    $base is optional, and defaults to 10.

EXPORT
    &interval2prefix is exported by default.

BUGS
    Please report any bugs via CPAN RT:

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

    or by sending mail to

      bug-Algorithm-Interval2Prefix@rt.cpan.org

AUTHOR
    Lars Thegler <lars@thegler.dk>

COPYRIGHT
    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.

--cut--



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About