Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在Perl中将参数传递给方法_Arrays_Perl_Object_Methods_Parameter Passing - Fatal编程技术网

Arrays 如何在Perl中将参数传递给方法

Arrays 如何在Perl中将参数传递给方法,arrays,perl,object,methods,parameter-passing,Arrays,Perl,Object,Methods,Parameter Passing,我正在尝试使用这个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

我正在尝试使用这个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;
正如您在上面的代码片段中所看到的,我希望将现有数组传递给对象

我怎样才能正确地做到这一点

目前我得到了这样一个例外:
HTML::Highlight—“words”和“wildcards”参数必须是对C:\Skripts\Perl\syntax\u Highlight.pl第8行数组的引用。

如错误消息中所述,传递一个引用:

my $hl = HTML::Highlight->new(
    words => \@keywords,
#     here __^
    wildcards => [
            undef,
    ],
    colors => [
            'red; font: bold',
    ],
    debug => 0
);

如错误消息中所述,传递引用:

my $hl = HTML::Highlight->new(
    words => \@keywords,
#     here __^
    wildcards => [
            undef,
    ],
    colors => [
            'red; font: bold',
    ],
    debug => 0
);