in reply to Sorting text-number values
#!/usr/bin/perl # http://perlmonks.org/?node_id=1176809 use strict; use warnings; print sort {$a =~ s/.*[^\d\n]//r <=> $b =~ s/.*[^\d\n]//r} <DATA>; __DATA__ this_5_string_12 some_12_garbage_23 this_5_string_8 17 this_5_string_23 some_12_garbage_6 102 this_5_string_19 5 this_5_string_101
Outputs:
5 some_12_garbage_6 this_5_string_8 this_5_string_12 17 this_5_string_19 some_12_garbage_23 this_5_string_23 this_5_string_101 102
Is this what you want as sort order?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting text-number values
by merrymonk (Hermit) on Nov 30, 2016 at 08:36 UTC |