in reply to Re^2: Noodling with natural sorting in perl6
in thread Noodling with natural sorting in perl6

That way you duplicated the transformation code.

Here's a version that uses neither temporaries nor duplicated code:

sub natural_cmp ($a is copy, $b is copy) { return [cmp] ($a, ).map: *.subst(/(\d+)/, -> $/{ sprintf( "%s%c%s", + 0, $0.chars, $0) }, :g).lc }

This uses the reduction meta operator.

Perl 6 - links to (nearly) everything that is Perl 6.