in reply to sorting an array

# 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.


The zeroeth step in writing a module is to make sure that there isn't already a decent one in CPAN. (-- Pod::Simple::Subclassing)