【发布时间】:2015-01-29 08:53:33
【问题描述】:
我正在尝试使用这个 Perl 方法:HTML::Highlight - 一个用于突出显示 HTML 文档中的单词或模式的模块。
方法本身并不是问题,而是我如何传递属性的方式。
有效的示例:
use HTML::Highlight;
$text = 'Lorem ipsum Velit ullamco ex anim quis Duis laboris ut proident velit eu dolor Ut amet proident aliqua minim officia sunt commodo veniam dolor id reprehenderit reprehenderit non nulla incididunt mollit exercitation minim commodo ut quis laboris ex proident.';
# create the highlighter object
my $hl = new HTML::Highlight (
words => [
'ex',
'ul',
],
wildcards => [
undef,
],
colors => [
'red; font: bold',
],
debug => 0
);
my $hl_document = $hl->highlight($text);
print $hl_document;
我想做的是这样的:
use HTML::Highlight;
$text = 'Lorem ipsum Velit ullamco ex anim quis Duis laboris ut proident velit eu dolor Ut amet proident aliqua minim officia sunt commodo veniam dolor id reprehenderit reprehenderit non nulla incididunt mollit exercitation minim commodo ut quis laboris ex proident.';
# create the highlighter object
@keywords = "ex", "ul";
my $hl = new HTML::Highlight (
words => @keywords,
wildcards => [
undef,
],
colors => [
'red; font: bold',
],
debug => 0
);
my $hl_document = $hl->highlight($text);
print $hl_document;
正如您在上面的代码 sn-p 中看到的,我想将现有数组传递给对象。
我怎样才能正确地做到这一点?
目前我得到这样的例外: HTML::Highlight - “单词”和“通配符”参数必须引用 C:\Skripts\Perl\syntax_highlight.pl 第 8 行中的数组。
【问题讨论】:
标签: arrays perl object methods parameter-passing