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

Task

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

Details

* An OID consists of one or more non-negative integers in base 10, separated by dots. It starts and ends with a number.
* Their natural sort order is lexicographical with regard to the dot-separated fields, using numeric comparison between fields.

Test case

:   :   :   :   | Input *(list of strings)* | Output *(list of strings)* |
                | --- | --- |
                | `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` | `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` |

Related tasks

* Natural sorting
* Sort using a custom comparator

---
assistant
(formerly Perl 6)

The sort 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.

```
.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
>;

```

Output:

```
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

```

Alternatively, using the sprintf-based approach used by the Perl solution, for comparison *(input elided)*:

```
.say for sort *.split('.').fmt('%08d'), <...>;

```

Or if using a third-party module is acceptable:

```
use Sort::Naturally;

.say for sort &naturally, <...>;

```