Perl 字符串转义字符
Perl 字符串转义字符
所有特殊字符或符号,如@、#、$、&/、\ 等都不会以正常方式打印。他们需要一个前面的转义字符反斜杠(\) 来打印。
Perl 显示电子邮件地址
所有电子邮件地址都包含(@) 符号。如前所述,符号不会在字符串中正常打印。他们需要额外的关注。在@ 符号前使用反斜杠(\) 打印电子邮件地址。
use strict;
use warnings;
my $site = "lidihuo\@gmail.com";
print"$site\n";
输出:
"/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="553f34233421253a3c3b21153238343c397b363a38">[email protected]
Perl $ 符号嵌入双引号字符串
如果我们想在字符串中打印($) 符号,请在 $ 符号前使用反斜杠(\)。
use strict;
use warnings;
my $msg1 = 'Ana';
print"We have defined \$msg1 as $msg1\n";
输出:
We have defined $msg1 as Ana
Perl 转义转义符
如果我们想在字符串中打印(\) 符号,请在 \ 符号之前使用反斜杠(\)。
use strict;
use warnings;
print"The \\n is a new line chracter in programming languages.\n";
输出:
Everyone has to follow this rule whether its a boy\girl
Perl 转义双引号
如果要在字符串内打印双引号,请在两个引号处使用反斜杠(\)。
use strict;
use warnings;
my $x = 'tutorials';
print"Our site \"lidihuo\" provides all type of \"$x\"\n";
输出:
Our site "lidihuo" provides all type of "tutorials?
Perl Double-q 运算符,qq
"qq"运算符用括号替换字符串周围的双引号。这意味着("") 在此字符串中不再重要。它将简单地用 qq 打印字符串。
但是如果你想在字符串中使用括号,那么你需要在字符串周围使用花括号 {}。
如果你需要花括号在字符串内使用大括号,然后在字符串周围使用方括号 []。
#use of qq
use strict;
use warnings;
my $x = 'tutorials';
printqq(Our site "lidihuo" provides all type of "$x"\n);
#use of {} brackets
printqq{Our site (lidihuo) provides all type of "$x"\n};
#use of [] brackets
printqq[Our site (lidihuo} provides all type of "$x"\n];
输出:
Our site "lidihuo" provides all type of "tutorials"
Our site (lidihuo) provides all type of "tutorials"
Our site (lidihuo} provides all type of "tutorial"
Perl Single-q 运算符,q
单个 'q' 运算符用作字符串中的单引号(')。与单引号一样,它也不插入变量。
#use of q
use strict;
use warnings;
my $x = 'tutorials';
printq(Our site "lidihuo" provides all type of "$x"\n);
print"\n";
#use of () brackets
printq(Our site "lidihuo" provides all type of "$x"\n);
print"\n";
#use of {} brackets
printq{Our site )lidihuo( provides all type of "$x"\n};
print"\n";
#use of {} brackets
printq[Our site )lidihuo} provides all type of "$x"\n];
输出:
Our site "lidihuo" provides all type of "$x"\n
Our site "lidihuo" provides all type of "$x" \n
Our site )lidihuo( provides all type of "$x" \n
Our site )lidihuo} provides all type of "$x" \n