in reply to Sort::Key::Natural sorting discrepancy
If I understand well what you want, this might be your solution:
This produces the following output:use strict; use warnings; use feature 'say'; my @list = qw(P007b_Yum P007_Yum P007B_YUM P007_YUM P007b_yum P007_yum +); my @sorted = sort { lc $a cmp lc $b } sort { $b cmp $a } @list; say for @sorted;
The first sort (on the right-hand side) puts the list in the right order with respect to words having the same letters but in different cases, the second sort (on the left) then deals with underscores versus letters. This works because the sort algorithm used (merge sort) is stable, so that items that compare equal when changed to lower case (second sort) are kept in the same order as determined by the first sort.$ perl sort_lc.pl P007_yum P007_Yum P007_YUM P007b_yum P007b_Yum P007B_YUM
If this is still not the order you want, please let us know what you expect.
|
|---|