Reputation: 762
I am using HTML::Entities module to encode some special chars. Here is my sample code:
use HTML::Entities qw(encode_entities_numeric);
my $str = "some special chars like € ™ © ®";
encode_entities_numeric($str);
print $str;
Output: € ™ © ®
As output is in HTML numeric hex code of the char.
I want output in form of HTML numeric decimal value of the chars like € ™ © ®
Is there a way to do this in encode_entities_numeric()
Upvotes: 1
Views: 666
Reputation: 132802
HTML::Entities does the conversion in a little sub named num_entry
. Redefine that to be whatever you want:
use utf8;
use HTML::Entities qw(encode_entities_numeric);
{
no warnings 'redefine';
sub HTML::Entities::num_entity { sprintf "&#%d;", ord($_[0]); }
}
my $str = "some special chars like € ™ © ®";
encode_entities_numeric($str);
print $str;
For what it's worth, this is the sort of thing Perl wants you to do. It's designed so that you can change things in this manner. It would be nicer if HTML::Entities were set up to allow derived classes, but it's not. Perl, recognizing that the world is messy like this, has ways for you to adjust that for what you need.
Upvotes: 3
Reputation: 385764
No, it's not configurable (because €
and €
are 100% equivalent in HTML).
Upvotes: 1