in reply to How can I sort my array numerically on part of the string?
You were sooo close...
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11124461 use warnings; my @list = ( '1,cat', '2,dog', '22,mouse', '11,eel', '001,elk', '13,mi +nk'); print join "\n", sort { $a=~s/,.+//r <=> $b =~ s/,.+//r } @list;
Outputs:
1,cat 001,elk 2,dog 11,eel 13,mink 22,mouse
|
---|
In Section
Seekers of Perl Wisdom