本文介绍了perl中m/PATTERN/和/PATTERN/之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

Perl中以下代码段之间是否有技术上的区别?它们的行为似乎相同

Is there any technical difference between the following code segments in perl? They seem to behave identical

my $str = "A cat is red";

if($str =~ /cat/) {
    print "Matches\n";
}

vs

my $str = "A cat is red";

if($str =~ m/cat/) {
    print "Matches\n";
}

此代码中的区别是第3行上的"m".为什么有人省略或不省略"m"?

The difference in this code is the "m" on line 3. Why would someone omit or not omit the "m"?

推荐答案

请参见 RegExp类似报价的操作符文档:它们是相同的. m版本"允许您使用其他字符代替/作为分隔符.但除此之外,没有区别.

See the RegExp Quote-Like Operators documentation: they're identical. The m "version" allows you to use other characters instead of / as a separator. But apart from that, no difference.

这篇关于perl中m/PATTERN/和/PATTERN/之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-09 01:04