# first num sub num_from_str { my $str = shift; my ($num) = $str =~ /(\d+)/; return $num; } my @a = qw( ch1 ch11 ch55 ch5 ch2 ch16 ); my @sorted = sort { num_from_str($a) <=> num_from_str($b) } @a; print "$_\n" for @sorted;
update: ... but Sort::Key::Natural is a more complete solution, because it sorts based on the alphabetical bits as well.
In reply to Re: sorting an array
by missingthepoint
in thread sorting an array
by Selvakumar
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |