Reputation: 14078
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?
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.
Upvotes: 4
Views: 205
Reputation: 241958
Use the vianame
function from charnames:
perl -CO -Mcharnames=:full -wE 'say chr charnames::vianame("PILE OF POO")'
💩
Upvotes: 10
Reputation: 98398
use charnames ();
my $what = "FAMILY";
say charnames::string_vianame($what);
Upvotes: 5