Sort a list of object identifiers: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 106:
1.3.6.1.4.1.11150.3.4.0.1
</pre>
 
=={{header|AWK}}==
<lang AWK>
Line 650 ⟶ 651:
readInt :: String -> Int
readInt x = read x :: Int</lang>
 
=={{header|jq}}==
<lang jq>def data: [
"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"
];
 
data | map( split(".") | map(tonumber) ) | sort | map(join("."))</lang>
 
{{out}}
<pre>[
"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.1",
"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.10",
"1.3.6.1.4.1.11150.3.4.0",
"1.3.6.1.4.1.11150.3.4.0.1"
]</pre>
 
=={{header|J}}==
Line 747 ⟶ 726:
1.3.6.1.4.1.11150.3.4.0
1.3.6.1.4.1.11150.3.4.0.1</pre>
 
=={{header|jq}}==
<lang jq>def data: [
"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"
];
 
data | map( split(".") | map(tonumber) ) | sort | map(join("."))</lang>
 
{{out}}
<pre>[
"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.1",
"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.10",
"1.3.6.1.4.1.11150.3.4.0",
"1.3.6.1.4.1.11150.3.4.0.1"
]</pre>
 
=={{header|Julia}}==
Line 1,081 ⟶ 1,082:
map { [$_, eval "v$_"] }
@OIDs;</lang>
 
=={{header|Perl 6}}==
 
The <tt>sort</tt> routine accepts a sort key callback as the first argument. Here we generate a list of integers as the sort key for each OID, which gets sorted lexicographically with numeric comparison by default.
 
<lang perl6>.say for sort *.comb(/\d+/)».Int, <
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
>;</lang>
 
{{out}}
<pre>
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.1
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.10
1.3.6.1.4.1.11150.3.4.0
1.3.6.1.4.1.11150.3.4.0.1
</pre>
 
Alternatively, using the <tt>sprintf</tt>-based approach used by the Perl solution, for comparison ''(input elided)'':
 
<lang perl6>.say for sort *.split('.').fmt('%08d'), <...>;</lang>
 
Or if using a third-party module is acceptable:
 
<lang Perl6>use Sort::Naturally;
 
.say for sort &naturally, <...>;</lang>
 
=={{header|Phix}}==
Line 1,215 ⟶ 1,183:
"1.3.6.1.4.1.11150.3.4.0.1")))</lang>
Tests run with no output, indicating success.
 
=={{header|Raku}}==
(formerly Perl 6)
 
The <tt>sort</tt> routine accepts a sort key callback as the first argument. Here we generate a list of integers as the sort key for each OID, which gets sorted lexicographically with numeric comparison by default.
 
<lang perl6>.say for sort *.comb(/\d+/)».Int, <
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
>;</lang>
 
{{out}}
<pre>
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.1
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.10
1.3.6.1.4.1.11150.3.4.0
1.3.6.1.4.1.11150.3.4.0.1
</pre>
 
Alternatively, using the <tt>sprintf</tt>-based approach used by the Perl solution, for comparison ''(input elided)'':
 
<lang perl6>.say for sort *.split('.').fmt('%08d'), <...>;</lang>
 
Or if using a third-party module is acceptable:
 
<lang perl6>use Sort::Naturally;
 
.say for sort &naturally, <...>;</lang>
 
=={{header|REXX}}==
Line 1,608 ⟶ 1,610:
1.3.6.1.4.1.11150.3.4.0.1
</pre>
 
 
=={{header|zkl}}==
10,327

edits