Algorithm-Interval2Prefix
view release on metacpan or search on metacpan
Interval2Prefix.pm view on Meta::CPAN
return $n / _step($i, $base);
});
}
sub interval2regex {
my($lo, $hi) = @_;
my @res = _i2a($lo, $hi, 10,
sub {
my($n, $i, $base)= @_;
my $p = $n / _step($i, $base);
my $s = length($n) - length($p);
return $p . ($s ? '\d' . ($s > 1 ? "{$s}" : '') : '');
});
return unless @res;
return '^(?:' . join('|', @res) . ')$';
}
1;
=head1 NAME
Interval2Prefix.pm view on Meta::CPAN
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 B<only> those numbers in the interval.
=head1 FUNCTIONS
Interval2Prefix.pm view on Meta::CPAN
Both interval2prefix() and interval2regex() are exported by default.
=head1 BUGS/TODO
=over 4
=item *
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.
=item *
interval2regex() only does base 10.
=back
Please report issues via CPAN RT:
( run in 0.240 second using v1.01-cache-2.11-cpan-65fba6d93b7 )