note
kcott
<p>G'day [id://161890|Lady Aleena],</p>
<blockquote>
<em>"I just can not come up with a list where this might be needed on alphabetical strings."</em>
</blockquote>
<p>
With <c>split_sort()</c>, as currently written, I can't see any use for the alpha sort type:
it will return the same as a plain <c>sort</c> (in all cases, as far as I can tell).
</p>
<p>
With an alpha sort type ignoring case, you could get this difference:
</p>
<code>
$ perl -E 'my @x = ("ade:Y", "Abc:X", "Afg:Z"); say for sort @x'
Abc:X
Afg:Z
ade:Y
$ perl -E 'my @x = ("ade:Y", "Abc:X", "Afg:Z"); say for sort { fc($a) cmp fc($b) } @x'
Abc:X
ade:Y
Afg:Z
</code>
<p>
With an alpha sort type expecting Unicode, you could get this difference:
</p>
<code>
$ perl -C -E 'my @x = ("\x{c5}de:Y", "Abc:X", "Afg:Z"); say for sort @x'
Abc:X
Afg:Z
Åde:Y
$ perl -MUnicode::Collate -C -E 'my @x = ("\x{c5}de:Y", "Abc:X", "Afg:Z"); say for Unicode::Collate->new->sort(@x)'
Abc:X
Åde:Y
Afg:Z
</code>
<blockquote>
<em>"I am now thinking that I should just put a note in saying that the alphabetical usage is redundant."</em>
</blockquote>
<p>
Perhaps not entirely redundant.
Consider its potential use in a scenario where you process an AoA
which holds a mixture of numeric and alphabetic arrays.
</p>
<code>
my @multi_sorts = (
[ $array1, ':', 'num' ],
[ $array2, '-', 'alpha' ],
[ $array3, ',', 'num' ],
);
handle_multi_mixed_sorts(\@multi_sorts);
# At this point in the code, each of the arrays in @multi_sorts
# has the original array still as the first element
# and the sorted array now as the fourth element.
sub handle_multi_mixed_sorts {
my ($multi_sorts) = @_;
for my $i (0 .. $#$multi_sorts) {
push @{$multi_sorts->[$i]}, [
sort { split_sort($a, $b,
$multi_sorts->[$i][1], $multi_sorts->[$i][2])
} @{$multi_sorts->[$i][0]}
];
}
return;
}
</code>
<p>
Do note that I just typed that code directly into my post:
it's entirely untested.
</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-861371">
<p>— Ken</p>
</div></div>
11119799
11119799