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

时间:2014-07-24 15:06:55

标签: 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})

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

没有运气。

1 个答案:

答案 0 :(得分:1)

use Regexp::Common::net;错了。将其更改为use Regexp::Common 'net';后,我就停止了该错误。

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