Then, in your sort, you now compare in the following:map { [ $_, /(?:(\d+)\s+)?(\w)\s+(\d+):(\d+)/ ] }
The reason for both defined checks is that you need to make sure that both sides have a number. You might have '1 Hebrews' vs. 'Hebrews'. You don't want to try and make that comparison. If you wanted, you could fake 'Hebrews' into '0 Hebrews' by improving the sort a bit to saysort { $a->[2] cmp $b->[2] || ( defined $a->[1] && defined $b->[1] && $a->[1] <=> $b->[1]) || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] }
Putting it all together, you end up with:sort { $a->[2] cmp $b->[2] || ($a->[1] || 0) <=> ($b->[1] || 0) || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] }
(Note - this is untested code. Caveat Emptor!)@sorted = map { $_-[0] } sort { $a->[2] cmp $b->[2] || ($a->[1] || 0) <=> ($b->[1] || 0) || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] } map { [ $_, /(?:(\d+)\s+)?(\w)\s+(\d+):(\d+)/ ] } @unsorted;
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
In reply to Re: Inconsistent column Schwartzian Transform attempt
by dragonchild
in thread Inconsistent column Schwartzian Transform attempt
by gryphon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |