How to resolve the algorithm Sort a list of object identifiers step by step in the Perl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sort a list of object identifiers step by step in the Perl programming language

Table of Contents

Problem Statement

Object identifiers (OID) are strings used to identify objects in network data.

Show how to sort a list of OIDs, in their natural sort order.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sort a list of object identifiers step by step in the Perl programming language

Source code in the perl programming language

my @OIDs = qw(
    1.3.6.1.4.1.11.2.17.19.3.4.0.10
    1.3.6.1.4.1.11.2.17.5.2.0.79
    1.3.6.1.4.1.11.2.17.19.3.4.0.4
    1.3.6.1.4.1.11150.3.4.0.1
    1.3.6.1.4.1.11.2.17.19.3.4.0.1
    1.3.6.1.4.1.11150.3.4.0
);

my @sorted =
    map { $_->[0] }
    sort { $a->[1] cmp $b->[1] }
    map { [$_, join '', map { sprintf "%8d", $_ } split /\./, $_] }
    @OIDs;

print "$_\n" for @sorted;


my @sorted =
    map { $_->[0] }
    sort { $a->[1] cmp $b->[1] }
    map { [$_, eval "v$_"] }
    @OIDs;


  

You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Rust programming language
You may also check:How to resolve the algorithm Comments step by step in the SPL programming language
You may also check:How to resolve the algorithm Paraffins step by step in the Wren programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Z80 Assembly programming language
You may also check:How to resolve the algorithm Selectively replace multiple instances of a character within a string step by step in the Raku programming language