http://qs1969.pair.com?node_id=436578

ministry has asked for the wisdom of the Perl Monks concerning the following question:

I have a list containing various names, some with a numeric suffix and some without. For example my list would contain (file1...file20), (server1...server20), & (ps,df,find,etc...). I would like to sort this list first by an alpha comparison, and secondly by a numeric value comparison.

Here's what I have so far:

@pretty=sort { my @a = $a =~ /(\D+)(\d+)/; my @b = $b =~ /(\D+)(\d+)/; $a[0] cmp $b[0] || $a[1] <=> $b[1] } @not_so_pretty;

This is as close as I have come to getting what I need, unfortunately this sort will return the elements of my list that do not contain numeric characters at the top of the list, as opposed to the required method of an alpha comparison first.

Regards, Ev