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
    First a general thank you to all who have suggestions to my query.

    It so happens that the first part of johngg’s method has given the order I was looking for. However, the additional parts of his and other suggestions just shows me how careful you have to be in specifying what is wanted and also just how many ways there are ‘to boil an egg”!