in reply to sorting number
G'day dideod.yang,
What you have as "I want to print ..." is not really sorted. Perhaps you wrote COREA12 and COREA115 around the wrong way. If that's the case, you'd need to split each element into alphabetic and numeric parts but do a string comparison on both of them:
$ perl -E ' say map "$_->[0]$_->[1] ", sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } map [/(\D+)(\d+)/], qw{ CORE1 CORE12 CORE8 CORE233 COREA11 COREA12 COREA130 COREA115 } ' CORE1 CORE12 CORE233 CORE8 COREA11 COREA115 COREA12 COREA130
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sorting number
by Eily (Monsignor) on Apr 09, 2019 at 07:58 UTC | |
by kcott (Archbishop) on Apr 09, 2019 at 08:24 UTC | |
|
Re^2: sorting number
by AnomalousMonk (Archbishop) on Apr 09, 2019 at 08:00 UTC | |
by kcott (Archbishop) on Apr 09, 2019 at 08:29 UTC |