G'day Laurent,
An alternative to this could be a Guttman-Rosler Transform. In the following, I've kept the same data, in the same order; and, I retained the same basic code layout for the transform.
#!/usr/bin/env perl -l use strict; use warnings; my @array = qw{ Patch_11.4 Patch_1.0 Patch_2.0 Patch_3.1 Patch_5.0 Patch_4.2 Patch_6.0 Patch_11.0 Patch_7.0 Patch_8.0 Patch_9.3 Patch_10.2 Patch_11.2 }; @array = map substr($_, 2), sort map pack("C2", /^Patch_(\d+)\.(\d+)/) . $_, @array; print for @array;
The output is identical to what you show.
Just as a side note, given the list context provided by "[ ... ]", regex captures will be evaluated in that context, and your second map would only need a single statement. Here's a quick one-liner to explain:
$ perl -E 'my @x = qw{X1.2 X3.4}; say "@$_" for map { [ $_, /X(\d+)\.( +\d+)/ ] } @x' X1.2 1 2 X3.4 3 4
— Ken
In reply to Re^2: sorting an array with decimal points
by kcott
in thread sorting an array with decimal points
by levW
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |