/ Published in: Perl
I love this one. Needed a good way to numerically sort IP addresses or OIDs. Took longer to come up with this than I'm willing to admit. Hope others find it useful.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
=head2 oidSort Accepts an array or an array reference of Object Identifiers (OIDs) or IP addresses. Returns a numerically sorted array or array reference, depending upon how the method is called. Returns 1 if nothing is passed, returns -1 if a reference to something other than an array is passed. =cut sub oidSort { my ( @oids, @_oids, $oid ); if ( !$_[ 0 ] ) { } @_oids = @{ $_[ 0 ] }; } @_oids = @_; } else { } map { my $oid = $_; $oid =~ s/^\.//; $oid =~ s/ /\.0/g; } @_oids; }