Sort a list of object identifiers: Difference between revisions
Content added Content deleted
Catskill549 (talk | contribs) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 106: | Line 106: | ||
1.3.6.1.4.1.11150.3.4.0.1 |
1.3.6.1.4.1.11150.3.4.0.1 |
||
</pre> |
</pre> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<lang AWK> |
<lang AWK> |
||
Line 650: | Line 651: | ||
readInt :: String -> Int |
readInt :: String -> Int |
||
readInt x = read x :: Int</lang> |
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}}== |
=={{header|J}}== |
||
Line 747: | Line 726: | ||
1.3.6.1.4.1.11150.3.4.0 |
1.3.6.1.4.1.11150.3.4.0 |
||
1.3.6.1.4.1.11150.3.4.0.1</pre> |
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}}== |
=={{header|Julia}}== |
||
Line 1,081: | Line 1,082: | ||
map { [$_, eval "v$_"] } |
map { [$_, eval "v$_"] } |
||
@OIDs;</lang> |
@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}}== |
=={{header|Phix}}== |
||
Line 1,215: | Line 1,183: | ||
"1.3.6.1.4.1.11150.3.4.0.1")))</lang> |
"1.3.6.1.4.1.11150.3.4.0.1")))</lang> |
||
Tests run with no output, indicating success. |
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}}== |
=={{header|REXX}}== |
||
Line 1,608: | Line 1,610: | ||
1.3.6.1.4.1.11150.3.4.0.1 |
1.3.6.1.4.1.11150.3.4.0.1 |
||
</pre> |
</pre> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |