Retrieving a Unicode code point ("character") by name

Perl makes it easy to get a character.

$ perl -CO -E 'say "\N{FAMILY}"'
👪

Is there a way to evaluate a character using "\N{}"interpolation? Something like:

perl -CO -E 'my $what = "FAMILY"; say "\N{$what}"'

(which doesn't work, but gives you a taste).

Besides feasibility, is there any flaw or possible threat to such an assessment? For instance. let's say the string $whatis user defined, I would never eval $what. Safe I \N{$what}?

Oops ...

After receiving the answers, I noticed how this information is clearly indicated in perlunicook. Sorry for the lack of RTFM. I think this is good if you use stackoverflow anyway.

+4
source share
2 answers

vianame charnames:

perl -CO -Mcharnames=:full -wE 'say chr charnames::vianame("PILE OF POO")'
💩
+9
use charnames ();
my $what = "FAMILY";
say charnames::string_vianame($what);
+4

All Articles