#!/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?
In reply to Re: Sorting text-number values
by tybalt89
in thread Sorting text-number values
by merrymonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |