Sort using a custom comparator: Difference between revisions
m
→{{header|Perl}}: sundry clean-up
Alextretyak (talk | contribs) m (→{{header|11l}}) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: sundry clean-up) |
||
Line 2,861:
=={{header|Perl}}==
<lang perl>use feature 'say';
<lang perl>sub mycmp { length $b <=> length $a || lc $a cmp lc $b }▼
# with a subroutine:
Or inline:▼
say join ' ', sort {length $b <=> length $a || lc $a cmp lc $b} @strings
my @sorted = map { $_->[0] }▼
# for large inputs, can be faster with a 'Schwartzian' transform:
sort { $a->[1] <=> $b->[1] || $a->[2] cmp $b->[2] }▼
map { [ $_, length, lc ] }
@strings;</lang>
{{out}}
<pre>strings sample sorted Here some are be to
strings sample sorted Here some are be to
strings sample sorted Here some are be to</pre>
=={{header|Phix}}==
|