Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

unicode

perl

Perl makes it very convenient to get some symbol.

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

Is there a way to evaluate the symbol with "\N{}" via interpolation? Something similar to:

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

(which does not work, but gives you the flavour).

Besides feasibility, is there any drawback or possible threat in such evaluation? E.g. say the $what string is user-defined, I would never eval $what. Would I \N{$what} safely?

Ops...

After getting the answers, I noticed how this information clearly stated in perlunicook. Sorry for the lack of RTFM. I guess this is a good thing to have on stackoverflow anyway.

like image 608
Dacav Avatar asked Dec 07 '22 22:12

Dacav


1 Answers

Use the vianame function from charnames:

perl -CO -Mcharnames=:full -wE 'say chr charnames::vianame("PILE OF POO")'
💩
like image 142
choroba Avatar answered Jan 10 '23 12:01

choroba