加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl RegEx语法错误

发布时间:2020-12-15 21:57:22 所属栏目:大数据 来源:网络整理
导读:以下从 http://perldoc.perl.org/perlrequick.html#Search-and-replace获取的代码片段给了我 Bareword found where operator expected at blub.pl line 2,near “s/dogs/cats/r” 这有什么问题?我在Windows XP上使用Perl 5.12.4. 码: $x = "I like dogs.";
以下从 http://perldoc.perl.org/perlrequick.html#Search-and-replace获取的代码片段给了我

Bareword found where operator expected at blub.pl line 2,near
“s/dogs/cats/r”

这有什么问题?我在Windows XP上使用Perl 5.12.4.

码:

$x = "I like dogs.";
$y = $x =~ s/dogs/cats/r;
print "$x $yn";

解决方法

您正在查看Perl 5.14的文档.该示例未出现在 the documentation for Perl 5.12中.

您可以看到它在perl 5.13.2 delta中被标记为新功能.

您可以复制该变量,然后对其进行修改以在旧版本的Perl中实现相同的效果.

$x = "I like dogs.";
$y = $x;
$y =~ s/dogs/cats/;
print "$x $yn";

或者你可以使用惯用的“单线”:

$x = "I like dogs.";
($y = $x) =~ s/dogs/cats/;
print "$x $yn";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读