in reply to Data with Letter(s) & Number sort query
Note that you did not specify any sort order for the letters when the digits are the same, so the items are kept in the original order in that case (see e.g. A1180, C1180 and D1180).$ perl -e 'use strict; > use warnings; > use Data::Dumper; > > my @a = qw / E1180 D250 A1180 E855 E975 A130 A250 B1105 B1255 B2480 +C1180 C1600 D1180 /; > > print "$_\n" > for map "$_->[0]$_->[1]", > sort { $a->[1] <=> $b->[1]} > map { /([A-Z]+)(\d+)/; [$1, $2]} @a;' A130 D250 A250 E855 E975 B1105 E1180 A1180 C1180 D1180 B1255 C1600 B2480
Update:: removed a piece a code that got accidentally pasted twice.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Data with Letter(s) & Number sort query
by Anonymous Monk on Nov 19, 2016 at 10:46 UTC | |
by Laurent_R (Canon) on Nov 19, 2016 at 11:02 UTC | |
by Laurent_R (Canon) on Nov 19, 2016 at 12:05 UTC | |
by merrymonk (Hermit) on Nov 19, 2016 at 14:05 UTC | |
by hippo (Archbishop) on Nov 19, 2016 at 14:21 UTC | |
by Laurent_R (Canon) on Nov 19, 2016 at 16:08 UTC |