Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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
尝试使用perl Regexp::Common::Net时出错_Regex_Perl - Fatal编程技术网

尝试使用perl Regexp::Common::Net时出错

尝试使用perl Regexp::Common::Net时出错,regex,perl,Regex,Perl,我正在尝试使用Regexp::Common::Net解析文本中的所有IP,如下所示: use strict; use Regexp::Common::net; if ($ids{$h} =~ /$RE{net}{IPv4}/) { print $1; } 但我一直在犯这样的错误: Global symbol "%RE" requires explicit package name at example.pl 我也尝试过: if ($ids{$h} =~ $RE{net}{IPv4}

我正在尝试使用Regexp::Common::Net解析文本中的所有IP,如下所示:

use strict;
use Regexp::Common::net; 
if ($ids{$h} =~ /$RE{net}{IPv4}/) {
    print $1;
}
但我一直在犯这样的错误:

Global symbol "%RE" requires explicit package name at example.pl
我也尝试过:

if ($ids{$h} =~ $RE{net}{IPv4})


没有运气。

使用Regexp::Common::net是错误的。将其更改为
后,使用Regexp::Common'net'我不再有那个错误了


编辑:为了工作,上面的代码段,正则表达式必须是:/$RE{net}{IPv4}{-keep}/

编写
use Regexp::common qw(net)
非常常见。这种方法的优点是可以在同一行中导入多个符号,例如
使用Regexp::Common qw(net CC)
Great。出于专业原因,我正在匆忙学习perl,我想知道qw()语句,但我还没有时间学习它们
qw
从字符串中的每个单独的单词生成一个列表,因此我前面的示例相当于
使用Regexp::Common(“net”,“CC”)
。我建议您查看上的文档,这是声明数组的一种非常简洁的方法。
if ($ids{$h} =~ m/$RE{net}{IPv4}/)