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:grep在常量数组中的应用_Arrays_Perl_Grep - Fatal编程技术网

Arrays perl:grep在常量数组中的应用

Arrays perl:grep在常量数组中的应用,arrays,perl,grep,Arrays,Perl,Grep,我想知道$myVar中的值是否存在于常量MY_数组中。以下内容似乎不起作用: use constant { MY_ARRAY => ['E1', 'E2'] }; . . my $myVar = 'E2'; if ( grep( /^$myVar$/, MY_ARRAY ) ) { ... } 您必须使用@{} if ( grep( $_ eq $myVar, @{+MY_ARRAY} ) ) { # ... } 这个怎么办?你能给我指一个说明为什么这里需要+的参考资料吗?这是

我想知道$myVar中的值是否存在于常量MY_数组中。以下内容似乎不起作用:

use constant {
  MY_ARRAY => ['E1', 'E2']
};
.
.
my $myVar = 'E2';
if ( grep( /^$myVar$/, MY_ARRAY ) ) {
...
}

您必须使用
@{}

if ( grep( $_ eq $myVar, @{+MY_ARRAY} ) ) {
  # ...
}

这个怎么办?你能给我指一个说明为什么这里需要+的参考资料吗?这是为了消除歧义。看见