📅  最后修改于: 2021-01-07 08:29:13             🧑  作者: Mango
所有特殊字符或符号(如@,#,$,&/,\等)均无法正常print。他们需要前面的转义字符反斜杠(\)才能打印。
所有电子邮件地址都包含(@)符号。如前所述,符号通常不会在字符串打印。他们需要特别注意。 @符号前使用反斜杠(\)来print电子邮件地址。
use strict;
use warnings;
my $site = "javatpoint\@gmail.com";
print "$site\n";
输出:
javatpoint@gmail.com
如果要在字符串print($)符号,请在$符号前面使用反斜杠(\)。
use strict;
use warnings;
my $msg1 = 'Ana';
print "We have defined \$msg1 as $msg1\n";
输出:
We have defined $msg1 as Ana
如果要在字符串print(\)符号,请在\符号前面使用反斜杠(\)。
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
如果要在字符串print双引号,请在两个引号处都使用反斜杠(\)。
use strict;
use warnings;
my $x = 'tutorials';
print "Our site \"javaTpoint\" provides all type of \"$x\"\n";
输出:
Our site "javaTpoint" provides all type of "tutorials?
“ qq”运算符用括号将字符串周围的双引号替换。这意味着(“”)在此字符串不再是必需的。它只会用qqprint字符串。
但是,如果要在字符串中使用括号,则需要在字符串周围使用大括号{}。
而且,如果您需要在字符串内使用花括号,则可以在字符串周围使用方括号[]。
#use of qq
use strict;
use warnings;
my $x = 'tutorials';
print qq(Our site "javaTpoint" provides all type of "$x"\n);
#use of {} brackets
print qq{Our site (javaTpoint) provides all type of "$x"\n};
#use of [] brackets
print qq[Our site (javaTpoint} provides all type of "$x"\n];
输出:
Our site "javaTpoint" provides all type of "tutorials"
Our site (javaTpoint) provides all type of "tutorials"
Our site (javaTpoint} provides all type of "tutorial"
单个'q'运算符用作字符串的单引号(')。像单引号一样,它也不插入变量。
#use of q
use strict;
use warnings;
my $x = 'tutorials';
print q(Our site "javaTpoint" provides all type of "$x"\n);
print"\n";
#use of () brackets
print q(Our site "javaTpoint" provides all type of "$x"\n);
print"\n";
#use of {} brackets
print q{Our site )javaTpoint( provides all type of "$x"\n};
print"\n";
#use of {} brackets
print q[Our site )javaTpoint} provides all type of "$x"\n];
输出:
Our site "javaTpoint" provides all type of "$x"\n
Our site "javaTpoint" provides all type of "$x" \n
Our site )javaTpoint( provides all type of "$x" \n
Our site )javaTpoint} provides all type of "$x" \n