如何为 HTML 编码字符串?

如何为 HTML 编码字符串?

问题描述:

我正在寻找一种在 Perl 中对字符串/对象进行 HTML 编码的简单方法.使用的附加包越少越好.

I'm looking for a simple way to HTML encode a string/object in Perl. The fewer additional packages used the better.

HTML::Entities 是你的朋友.

use HTML::Entities;
my $encoded = encode_entities( "foo & bar & <baz>" );