而不是将结果汇总到一行并将其打印在另一行中? 如果我有这个数据
my $a = 1;
my $b = 2;
目前,如果我想打印总和结果,我需要编写像这样的代码
my $tmp = $a+$b;
print "result=$tmp\n";
与
类似的东西是否与上述相同print "result=$a+$b\n";
答案 0 :(得分:4)
是;
print "Result = ", $a+$b, "\n";
答案 1 :(得分:4)
print "Result=", $a+$b, "\n"; # Multi-arg print
print "Result=".($a+$b)."\n"; # Concatenation
print "Result=${\( $a+$b )}\n"; # ref-deref trick (scalar context)
print "Result=@{[ $a+$b ]}\n"; # ref-deref trick (list context)
printf "Result=%s\n", $a+$b; # printf
print sprintf("Result=%s\n", $a+$b); # sprintf