Perl: Allowed Char in Identifiers (variable name, function name)

By Xah Lee. Date: .

Perl Identifiers Allow Unicode Letter Characters

Identifier names can have Unicode: Letter Character

use utf8;
use strict;

# variable with Unicode char
my $愛 = 4;
print "$愛\n";

# function with Unicode char
sub f愛 { return 2;}
print f愛();

Identifier cannot have emoji or arbitrary unicode char

# perl v5.32.1

use strict;
use utf8;

# identifier cannot be emoji

my $😂 = 3;

# error
# Unrecognized character \x{1f602}
# perl v5.32.1

use strict;
use utf8;

# identifier cannot be arbitrary unicode char

my $♥ = 3;

# error
# Unrecognized character \x{2665}

The exact rule is complicated. But basically, if the unicode is considered a Unicode Letter Character , then, it's ok. Heart ♥ (U+2665: BLACK HEART SUIT) and emoji are not letters.

Perl, unicode