alafarm has asked for the wisdom of the Perl Monks concerning the following question:

I've been using the following substitution to convert utf8 characters to character entities:
$data =~ s/([\x{80}-\x{FFFF}])/'&#' . ord($1) . ';'/gse;

So the registered trademark symbol (®) becomes ®

But now my output needs to be of the form: ®

What would be a similarly simple substitution or other way to make the conversion?

Replies are listed 'Best First'.
Re: UTF to character entities
by Anonymous Monk on Sep 28, 2011 at 21:00 UTC
    Sure sprintf '&#x%X;', ord $1 or stick with HTML::Entities encode_entities_numeric