Array:...an::IP(3pm)
β¨ NAME β¨
Array::IntSpan::IP β bestie, it's a module for arrays that use IP addresses as their indices π (like Array::IntSpan, but make it network).
This one ships with the Perl 5 docs, manual page Array:...an::IP(3pm). She's giving "old-school Perl but make it spicy" and I'm obsessed π
πΈ SYNOPSIS πΈ
use Array::IntSpan::IP;
my $foo = Array::IntSpan::IP->new(['123.45.67.0', '123.45.67.255', 'Network 1'],
['123.45.68.0', '123.45.68.127', 'Network 2'],
['123.45.68.128', '123.45.68.255', 'Network 3']);
print "The address 123.45.68.37 is on network ".$foo->lookup("\173\105\150\45").".\n";
unless (defined($foo->lookup(((123*256+45)*256+65)*256+67))) {
print "The address 123.45.65.67 is not on a known network.\n";
}
print "The address 123.45.68.177 is on network ".$foo->lookup("123.45.68.177").".\n";
$foo->set_range('123.45.68.128', '123.45.68.255', 'Network 4');
print "The address 123.45.68.177 is now on network ".$foo->lookup("123.45.68.177").".\n";
like. look at her go π¦ setup, lookups, a little set_range glow-up at the end, iconic behavior fr fr.
π DESCRIPTION π
So Array::IntSpan::IP takes all the advantages of Array::IntSpan and brings them to IP address indices. Anywhere you'd use an index in Array::IntSpan, you can use an IP address in Array::IntSpan::IP β and bestie, you get three formats to choose from π
The three accepted forms are:
π Dotted decimal
This is THE standard human-readable format for IP addresses, the one your group chat would recognize. The conversion checks that the octets are in the range 0-255 β no fake octets allowed. Example: '123.45.67.89'.
π§ Network string
A four character string representing the octets in network order. Example: "\173\105\150\131".
β Integer
An integer value representing the IP address. Example: ((123*256+45)*256+67)*256+89 or 2066563929.
β οΈ okay bestie listen up, this is the important caveat β οΈ
Note that the algorithm has no way of distinguishing between the integer values 1000 through 9999 and the network string format. It will presume network string format in these instances. For instance, the integer 1234 (representing the address '0.0.4.210') will be interpreted as "\61\62\63\64", or the IP address '49.50.51.52'.
This is unavoidable since Perl does not strongly type integers and strings separately and there is no other information available to distinguish between the two in this situation. π I do not expect that this will be a problem in most situations. Most users will probably use dotted decimal or network string notations, and even if they do use the integer notation the likelihood that they will be using the addresses '0.0.3.232' through '0.0.39.15' as indices is relatively low. so like. we're fine. probably. π
π₯ METHODS π₯
π ip_as_int
The class method Array::IntSpan::IP::ip_as_int takes as its one parameter the IP address in one of the three formats mentioned above and returns the integer notation. that's it. that's the whole method. she's simple, she's effective, she ate π
β¨
π AUTHOR π
Toby Everett, teverett@alascom.att.com β thank you king π«Ά
and that's the whole page bestie!! this one's from perl v5.34.0, dated 2022-05-27, and it lives in the User Contributed Perl Documentation section of the Array:...an::IP(3pm) manual. mwah π go index some IPs, you got this πΈ
π¦ where this page comes from
- debian bookworm: libarray-intspan-perl 2.004-2 Β· Artistic-2.0
- debian trixie: libarray-intspan-perl 2.004-2 Β· Artistic-2.0
- ubuntu noble: libarray-intspan-perl 2.004-2 Β· Artistic-2.0
- ubuntu resolute: libarray-intspan-perl 2.004-2 Β· Artistic-2.0
- ubuntu stonking: libarray-intspan-perl 2.004-2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms