Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: UTF encoded subroutine names

by haukex (Archbishop)
on Jan 30, 2021 at 10:48 UTC ( [id://11127682]=note: print w/replies, xml ) Need Help??


in reply to UTF encoded subroutine names

The difference between the two symbols you've posted here is that Σ is U+03A3 GREEK CAPITAL LETTER SIGMA, while ∫ is U+222B INTEGRAL. If you use ∑ instead, that's U+2211 N-ARY SUMMATION, the same error happens, and if you use ʃ, U+0283 LATIN SMALL LETTER ESH, the error doesn't happen. As per Identifier parsing, identifiers under use utf8; must start with a character matching (?[ ( \p{Word} & \p{XID_Start} ) + [_] ]), and as per perluniprops, items from the Unicode block "Mathematical Operators" don't match that rule. Unfortunately, these symbols aren't quite equivalent of course, but if you want to use them as names for Perl subroutines, you'll probably have to stick with the lookalikes. Update: I also find this very useful: Unicode Utilities: Character Properties.

use warnings; use 5.028; use experimental 'regex_sets'; use open qw/:std :utf8/; use charnames ':full'; my $PERL_IDENT_RE = qr/ (?[ ( \p{Word} & \p{XID_Start} ) + [_] ]) (?[ ( \p{Word} & \p{XID_Continue} ) ]) * /x; for my $c ( 0x2211, 0x03A3, 0x222B, 0x0283 ) { printf "%s U+%04X %s %s\n", chr($c), $c, charnames::viacode($c), chr($c) =~ /\A$PERL_IDENT_RE\z/ ? "matches" : "doesn't match"; }

Output:

∑ U+2211 N-ARY SUMMATION doesn't match
Σ U+03A3 GREEK CAPITAL LETTER SIGMA matches
∫ U+222B INTEGRAL doesn't match
ʃ U+0283 LATIN SMALL LETTER ESH matches

Update 2: BTW, also: Ʃ U+01A9 LATIN CAPITAL LETTER ESH matches.

Replies are listed 'Best First'.
Re^2: UTF encoded subroutine names
by pme (Monsignor) on Jan 30, 2021 at 10:55 UTC
    Thanks a lot.
        Oops, the error message did not remind me to my previous post. Or I just getting too old. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2026-04-19 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.