On Tue, 8 Mar 2016 13:29:40 -0800
Kenneth Wolcott <[email protected]> wrote:
> How do I call the built-in Perl sort function on an array of strings
> where the string is composed of one or more digits, followed by a tab
> which is followed by a string and I want the results to be sorted in
> reverse numeric order?
The best thing to do is write a sortkey function to extract the keys:
sub sortkey {
my $value = shift @_;
return split /\t/, $value, 2;
}
my @sorted = map { $_->[0] }
sort { $b->[1] <=> $a->[1] || $a->[2] cmp $b->[2] }
map { [ $_. sortkey( $_ ) ] }
@list;
--
Don't stop where the ink does.
Shawn
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/