Sort::Key::IPv4 - sort IP v4 addresses
use Sort::Key::IPv4 qw(ipv4sort); my @data = qw(1.1.1.1 1.1.1.0 1.1.1.2 2.1.0.3); my @sorted = ipv4sort @data; use Sort::Key::IPv4 qw(ipv4keysort); my @sorted = ipv4keysort { $_->ip_address } @hosts;
This module extends the Sort::Key family of modules to support sorting of IP v4 addresses and networks.
IPv4 addresses have to match the regular expression /^\d+\.\d+\.\d+\.\d+$/. For instance 192.168.20.102.
/^\d+\.\d+\.\d+\.\d+$/
192.168.20.102
IPv4 networks have to match the regular expression /^\d+\.\d+\.\d+\.\d+\/\d+$/. For instance 10.2.4.0/24.
/^\d+\.\d+\.\d+\.\d+\/\d+$/
10.2.4.0/24
The functions that can be imported from this module are:
returns the IPv4 addresses in @data sorted.
@data
returns the IPv4 addresses in @data sorted in descending order.
returns the elements on @array sorted by the IPv4 addresses resulting from applying them CALC_KEY.
@array
CALC_KEY
is similar to ipv4keysort but sorts the elements in descending order.
ipv4keysort
these functions are similar respectively to ipv4sort, ripv4sort, ipv4sortkey and ripv4sortkey, but they sort the array @data in place.
ipv4sort
ripv4sort
ipv4sortkey
ripv4sortkey
These functions sort network addreses (composed by an IP and a network length pair with and slash separatin them).
converts the IPv4 value to a 32 bits unsigned integer.
converts an string of the format "xxx.xxx.xxx.xxx/xxx" into two 32 bit unsigned numbers, the first representing the IP address and the second the network mask.
Sort::Key, Sort::Key::Maker
Report bugs by email or using the CPAN RT system at http://rt.cpan.org/.
This module is hosted at GitHub: http://github.com/salva/p5-Sort-Key-IPv4.
Copyright © 2007, 2009, 2012 by Salvador Fandiño, <sfandino@yahoo.com>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install Sort::Key::IPv4, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sort::Key::IPv4
CPAN shell
perl -MCPAN -e shell install Sort::Key::IPv4
For more information on module installation, please visit the detailed CPAN module installation guide.