This works (as suggested by [Coke]): define a sub suitable for the key types expected:
sub my-sort($a, $b) { $a.key cmp $b.key }
my $jstr = to-json %h, :pretty, :sorted-keys(&my-sort);
If multiple key types are expected, then the sub should use elsif or when to define what the user wants when a key pair is not directly comparable. For example, I used this sub for mixed Str and Int types:
TO BE COMPLETE A BIT LATER (when I get back to a real computer)
This works (as suggested by [Coke]): define a sub suitable for the key types expected:
If multiple key types are expected, then the sub should use elsif or when to define what the user wants when a key pair is not directly comparable. For example, I used this sub for mixed Str and Int types:
TO BE COMPLETE A BIT LATER (when I get back to a real computer)