
FishMonger
Veteran
Nov 21, 2010, 8:41 AM
Post #3 of 14
(1590 views)
|
|
Re: [char_boy] Perl 5.10 not backwards compatible with 5.8
[In reply to]
|
Can't Post
|
|
BTW, that sort routine was pulled from the perldoc. perldoc -f sort
.... .... # inefficiently sort by descending numeric compare using # the first integer after the first = sign, or the # whole record case-insensitively otherwise @new = sort { ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0] || uc($a) cmp uc($b) } @old; # same thing, but much more efficiently; # we'll build auxiliary indices instead # for speed @nums = @caps = (); for (@old) { push @nums, /=(\d+)/; push @caps, uc($_); } @new = @old[ sort { $nums[$b] <=> $nums[$a] || $caps[$a] cmp $caps[$b] } 0..$#old ]; # same thing, but without any temps @new = map { $_->[0] } sort { $b->[1] <=> $a->[1] || $a->[2] cmp $b->[2] } map { [$_, /=(\d+)/, uc($_)] } @old; .... ....
|