ePages 7.47.0 - DE_EPAGES/Core/API/Number.pm

Package DE_EPAGES::Core::API::Number

Number parsing tools

@EXPORT_OK
ParseIntegerRange
ElementOfIntegerRange
ParseIntegerList
ElementOfIntegerList
ExtendIntegerList

Functions

ElementOfIntegerList
ElementOfIntegerRange
ExtendIntegerList
ParseIntegerList
ParseIntegerRange

ElementOfIntegerList

Returns true if $Value is part of the given integer list

Syntax
my $InList = ElementOfIntegerList($Value, $Range);
Example
my $InList = ElementOfIntegerList(23, '0-22,24,32-42'); # false
Input
$Value (int)
the value to check
$List (string)
the integer list to check against
Return
$InRange (boolean)
0 if value is not in the given list, otherwise true

ElementOfIntegerRange

Returns true if $Value is inside the given integer range bounds.

Syntax
my $InRange = ElementOfIntegerRange($Value, $Range);
Example
my $InRange = ElementOfIntegerRange(23, '0-42'); # true
Input
$Value (int)
the value to check
$Range (string)
the range to use
Return
$InRange (boolean)
0 if value is not in the given range, otherwise true

ExtendIntegerList

Adds a value to a integer-list expression. Returns a new list. This function may alter the order of the elements in the list. Use only if the order of elements is not relevant.

Syntax
my $NewList = ExtendIntegerList($Value, $List);
Example
my $NewList = ExtendIntegerList(41, '23-40,42); # '23-42'
Input
$Value (int)
the value to add to the list
$List (string)
the integer list to add the value to
Return
$NewList (string)
the new integer list with the given value added to it

ParseIntegerList

Parses comma-separated integer lists. Is able to parse integer ranges as part of the list.

Syntax
my @Ints = ParseIntegerList($List);
Example
my @Ints = ParseIntegerList('23,42,666');
Input
$List (string)
input string
Return
@Ints (array)
array of integer values

ParseIntegerRange

Parse integer ranges in the notation 'min-max', returns the lower and upper bound of the range.

Syntax
my ($Min, $Max) = ParseIntegerRange($Range);
Example
my ($Min, $Max) = ParseIntegerRange('23-42');
Input
$Range (string)
input range
Return
$Min, $Max (integer)
lower and upper bound of the parsed range