misterperl has asked for the wisdom of the Perl Monks concerning the following question:
I have this array:
my @list = ( '1,cat', '2,dog', '22,mouse', '11,eel', '001,elk', '13,mink');
that I'd like to sort numerically based on the number in front of the comma, so I tried:
print join "\n", sort { ($a=~s/,.+//) <=> ( $b =~ s/,.+// ) } @list;
But I seem to get an alpha, non-numeric result, which has the added detriment of dropping off my animals...
I also tried approaches like "\A\d+$a" <=> "\A\d+$b" which the interpreter REALLY hated!1 2 22 11 001
TY Wise ones.
Back to
Seekers of Perl Wisdom