Using my quick-intuition, are these methods sorting on the earliest number
withing the string, ignoring the non-digits?
$ raku -e '.say for .sort: {m/ \d+ /.Int}'
$ raku -e '.say for .sort: +*.match: / \d+ /'
let's see
$ raku -e '.say for .sort: {m/ \d+ /.Int}'
it1
does2
not3
matter10
what20
the30letters40
say31
What's been interesting about this thread is not only the variety of
solutions, also that the solutions are for two different questions-
how to sort by alpha & numeric segments (b3b, a1a, c20c) => (a1a, b3b, c2c)
how to sort by a numeric segment only (b3b, a1a, c20c) => (a1a, b3b, c20c)
-y
On Thu, Mar 7, 2024 at 4:40 PM Ralph Mellor wrote:
> On Tue, Mar 5, 2024 at 7:01 AM ToddAndMargo via perl6-users
> wrote:
>
> > >> $ raku -e '.say for .sort(*.split(/\d+/,
> :kv).map({ (try .Numeric) // $_}).List)'
> > >>
> > >> Yippee!
>
> > > raku -e '.say for .sort: { .comb(/ \d+ | \D+
> /).map({ .Int // .self }).cache };'
> >
> > Awesome! Now I have two different methods!
>
> And now 4:
>
> $ raku -e '.say for .sort: {m/ \d+ /.Int}'
> bk1
> bk2
> bk10
> bk34
>
> or, same logic, but spelled differently:
>
> $ raku -e '.say for .sort: +*.match: / \d+ /'
> bk1
> bk2
> bk10
> bk34
>
> --
> love, raiph
>