本文介绍了Perl中的单引号和双引号有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Perl中,'
和"
有什么区别?
In Perl, what is the difference between '
and "
?
例如,我有2个变量,如下所示:
For example, I have 2 variables like below:
$var1 = '\(';
$var2 = "\(";
$res1 = ($matchStr =~ m/$var1/);
$res2 = ($matchStr =~ m/$var2/);
$res2
语句抱怨Unmatched ( before HERE mark in regex m
.
推荐答案
双引号使用变量扩展.单引号不
Double quotes use variable expansion. Single quotes don't
在双引号字符串中,您需要转义某些字符以阻止对它们的不同解释.用单引号引起来的字符串中没有(反斜杠除外,如果它是字符串中的最后一个字符)
In a double quoted string you need to escape certain characters to stop them being interpreted differently. In a single quoted string you don't (except for a backslash if it is the final character in the string)
my $var1 = 'Hello';
my $var2 = "$var1";
my $var3 = '$var1';
print $var2;
print "\n";
print $var3;
print "\n";
这将输出
Hello
$var1
Perl僧侣对此此处
这篇关于Perl中的单引号和双引号有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!