Sort a list of object identifiers: Difference between revisions

→‎{{header|Perl}}: clean up the solution, and update it to comply with the new task description
(J: update example to match changed task)
(→‎{{header|Perl}}: clean up the solution, and update it to comply with the new task description)
Line 364:
=={{header|Perl}}==
 
<lang perl>my @OIDs = qw(
{{update|Perl|the format description and test-case in the task description have been updated}}
". 1.3.6.1.4.1.11.2.17.19.3.4.0.10",
 
". 1.3.6.1.4.1.11.2.17.195.2.0.79",
<lang perl>
". 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",
#!/usr/bin/perl
". 1.3.6.1.4.1.11.2.17.19.3.4.0.1",
 
". 1.3.6.1.4.1.11150.3.4.0.2",
###--------------------------
### Sort: -OID - Numeric
### Bert Mariani 2016-07-07
###--------------------------
 
@arrayOID = () ;
@arrayOIDSorted = () ;
 
@arrayOID =
(
".1.3.6.1.4.1.11.2.17.19.3.4.0.10",
".1.3.6.1.4.1.11150.3.4.0.2",
".1.3.6.1.4.1.11.2.17.19.3.4.0.19",
".1.3.6.1.4.1.11150.3.4.0.1",
".1.3.6.1.4.1.11.2.17.19.3.4.0.22",
".1.3.6.1.4.1.11.2.17.19.3.4.0.2",
".1.3.6.1.4.1.11150.3.4.0.11",
".1.3.6.1.4.1.11.2.17.19.3.4.0.1",
".1.3.6.1.4.1.11.2.17.3773.0.2",
".1.3.6.1.4.1.11.2.17.19.2.0.79",
".1.3.6.1.4.1.11150.3.4.0.21",
".1.3.6.1.4.1.11.2.17.19.2.0.9",
".1.3.6.1.4.1.11.2.17.19.3.4.0.25",
".1.3.6.1.4.1.11.2.17.19.3.4.0.32",
".1.3.6.1.4.1.11.2.17.19.3.4.0.4",
".1.3.6.1.4.1.11.2.17.19.3.4.0.31",
".1.3.6.1.4.1.11.2.17.19.3.4.0.3",
".1.3.6.1.4.1.11.2.17.3773.0.1"
);
 
my @sorted =
### One big long line ... made readable
map { $_->[0] }
@arrayOIDSorted =
sort { $a->[1] <=> $b->[1] }
map { $_->[0] }
map { [$_, join '', map { sprintf( "%8d", $_) } split /\./, $_] }
sort { $a->[1] cmp $b->[1] }
@OIDs;
map { [ $_,
join '', map { sprintf("%8d",$_) }
split( /\./, $_)
]
}
@arrayOID;
 
print "$_\n" for @sorted;</lang>
print "\nAfter OID Sort \n\n";
$ptrN = 0;
$entry = 1;
 
while ( $arrayOIDSorted[$ptrN] )
{
print "$entry | $arrayOIDSorted[$ptrN] |\n" ;
$entry++;
$ptrN++;
}
 
print "\nEnd OID Sort \n\n";
</lang>
{{out}}
<pre>
".1.3.6.1.4.1.11.2.17.195.3.42.0.31",79
 
1 | .1.3.6.1.4.1.11.2.17.19.23.4.0.9 |1
2 | .1.3.6.1.4.1.11.2.17.19.23.4.0.79 |4
3 | .1.3.6.1.4.1.11.2.17.19.3.4.0.1 |10
4 | .1.3.6.1.4.1.11.2.17.1911150.3.4.0.2 |
5 | .1.3.6.1.4.1.11.2.17.1911150.3.4.0.3 |1
6 | .1.3.6.1.4.1.11.2.17.19.3.4.0.4 |
7 | .1.3.6.1.4.1.11.2.17.19.3.4.0.10 |
8 | .1.3.6.1.4.1.11.2.17.19.3.4.0.19 |
9 | .1.3.6.1.4.1.11.2.17.19.3.4.0.22 |
10 | .1.3.6.1.4.1.11.2.17.19.3.4.0.25 |
11 | .1.3.6.1.4.1.11.2.17.19.3.4.0.31 |
12 | .1.3.6.1.4.1.11.2.17.19.3.4.0.32 |
13 | .1.3.6.1.4.1.11.2.17.3773.0.1 |
14 | .1.3.6.1.4.1.11.2.17.3773.0.2 |
15 | .1.3.6.1.4.1.11150.3.4.0.1 |
16 | .1.3.6.1.4.1.11150.3.4.0.2 |
17 | .1.3.6.1.4.1.11150.3.4.0.11 |
18 | .1.3.6.1.4.1.11150.3.4.0.21 |
 
</pre>
 
Anonymous user