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

Mocha Monks,

I can find about 10,000 references to:

The module can also export the %char2entity and the %entity2char hashes, which contain the mapping from all characters to the corresponding entities (and vice versa, respectively).

But not a single one that actually says HOW to do that.

Would some kind person care to share the secret? My objective is to add characters to the default list.

Thanks.




Forget that fear of gravity,
Get a little savagery in your life.
  • Comment on HTML::Entities - export/modify %char2entity ?

Replies are listed 'Best First'.
Re: HTML::Entities - export/modify %char2entity ? (custom entities)
by ikegami (Patriarch) on Feb 11, 2008 at 20:44 UTC

    As for your actual objective:

    use HTML::Entities qw( decode_entities ); sub my_decode_entities { local $HTML::Entities::entity2char{egrave} = chr(232); return decode_entities(@_); }

    Another way:

    use HTML::Entities qw( _decode_entities ); { my %entity2char = ( %HTML::Entities::entity2char, egrave => chr(232), ); sub my_decode_entities { return map { _decode_entities($_, \%entity2char } @_; } }

    In both cases, you don't break anything (such as HTML generating functions) by modifying the hashes since the scope of the modifications has been limited.

    By the way, I wouldn't call it a "default" list. It should be comprehensive. If any HTML entities are not included, you should submit a bug report.

Re: HTML::Entities - export/modify %char2entity ? (import vars)
by ikegami (Patriarch) on Feb 11, 2008 at 20:37 UTC
    Just like functions:
    use HTML::Entities qw( %char2entity %entity2char );
Re: HTML::Entities - export/modify %char2entity ?
by Anonymous Monk on Feb 12, 2008 at 07:39 UTC
    perldoc Exporter