develooper Front page | perl.perl6.users | Postings from January 2019

Re: I need m/ help

Thread Previous | Thread Next
From:
Brad Gilbert
Date:
January 13, 2019 22:04
Subject:
Re: I need m/ help
Message ID:
CAD2L-T3iyfVm3XhAhvAXaafqAcB+p8-jzSHFGNDw_JbyrMpM=w@mail.gmail.com
<:Nl> matches a Number that is letter-like

I mean obviously `Ⅿ` (ROMAN NUMERAL ONE THOUSAND) looks like a letter.

There is also <:Nd> for Number digit,
and <:No> for other Numbers

If you want to find out the general category of a character you can
call `.uniprop`.

    say "1".uniprop; # Nd # Number digit
    say "Ⅿ".uniprop; # Nl # Number letter # (ROMAN NUMERAL ONE THOUSAND)
    say "¼".uniprop; # No # Number other

    say "m".uniprop; # Ll # Letter lowercase
    say "M".uniprop; # Lu # Letter uppercase
    say "ߢ".uniprop; # Lo # Letter other
    say "ῼ".uniprop; # Lt # Letter titlecase
    say "ʹ".uniprop; # Lm # Letter modifier # (MODIFIER LETTER PRIME)

    say (0..0x10ffff).map(*.uniprop).Set.keys.sort;
    # (Cc Cf Cn Co Cs Ll Lm Lo Lt Lu Mc Me Mn Nd Nl No Pc Pd Pe Pf Pi
Po Ps Sc Sk Sm So Zl Zp Zs)

These are all defined by Unicode.

The MODIFIER LETTER PRIME is particularly useful if you want to write code like:

    my \A = …;
    my \Aʹ = A + …;

That works because it is a letter.

Note that if you call it on a number you are asking for the uniprop of
the character with that codepoint.

    say "A".ord; # 65
    say 65.uniprop; # Lu # because A is an uppercase Letter

There is also a `.uniprops` for getting a sequence of unicode
properties for each character in a string.

    say "A5".uniprops; # (Lu Nd)
    say "A5".comb.map(*.uniprop); # (Lu Nd)

On Sun, Jan 13, 2019 at 2:42 AM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> On 1/12/19 3:04 PM, Timo Paulssen wrote:
> > On 12/01/2019 23:40, ToddAndMargo via perl6-users wrote:
> >> But this does not.  What is wrong with (<:N>**2)  ?
> >>
> >> $ perl6 -e 'my Str $Date=DateTime.now.Str; $Date~~m/ (<:N>**4) "-"
> >> (<:N>**2) "-" (<:Nl>**2) "T" .* /; print "$Date\n\t$0  $1  $2\n"'
> >> Use of Nil in string context
> >>    in block <unit> at -e line 1
> >> Use of Nil in string context
> >>    in block <unit> at -e line 1
> >> Use of Nil in string context
> >>    in block <unit> at -e line 1
> >> 2019-01-12T14:33:10.692302-08:00
> >>
> >>
> >> Many thanks,
> >> -T
> >
> >
> > Hi Todd,
> >
> > it looks like you have an accidental l in there: the third capture group
> > has <:Nl> instead of <:N>.
> >
> > Changing that makes it work for me
> >    - Timo
> >
>
> Hi Timo,
>
> Just out of curiosity, what is the difference between "Number (<:N>)"
> and "Number Like (<:Nl>)"?  What would they not be the same in this context?
>
> My latest:
>
> $ perl6 -e 'DateTime.now.Str ~~ m/ (<:N>+) "-" (<:N>+) "-" (<:N>+) "T"
> .* /; my Str $Po="$1$2x$0_"; $Po~~s/x20//;print "$Po\n";'
>
> 011319_
>
> I stuck the "x" in there so I would not clobber day = 20.
>
> -T

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About