On Tue, May 15, 2018 at 12:44:12AM -0700, ToddAndMargo wrote:
: "abcrd-12.3.4"  would be five letters, six numbers, and one
: I don't care.

Here's another approach:

    $ p6 '"abcrd-12.3.4".comb.classify(*.uniprop).say'
    {Ll => [a b c r d], Nd => [1 2 3 4], Pd => [-], Po => [. .]}

    $ p6 '"abcrd-12.3.4".comb.map(*.uniprop).Bag.say'
    Bag(Ll(5), Nd(4), Pd, Po(2))

    $ p6 '"abcrd-12.3.4".comb.map(*.uniprop).Bag<Ll Nd Po>.say'
    (5 4 2)

Whenever you want a histogram, consider using classify or bags.

It's a bit odd to count dots as numbers, so Unicode counts it as
Punctionation Other, but if you assume there or no other characters in
the Po category than dot, you can just add the Po to the Nd total.

Otherwise you might need to use classify and grep out the dots from the
Po category to count them.  (You can't use a bag for that approach since
it throws away the information on which Po character it saw.)

Alternately, you could just make a bag of the raw characters and then
use slicing to define each the category and add up the values for each
character

    $ p6 '"abcrd-12.3.4".comb.Bag{"a"..."z"}.sum.say'
    5
    $ p6 '"abcrd-12.3.4".comb.Bag{"0"..."9", "."}.sum.say'
    6

That's more ASCII friendly, but ASCII is not always your friend.  :-)

Larry

Reply via email to