为什么 Perl 中的“print (52-80)*42"与“print 42*(52-80)"不同? [英] Why is 'print (52-80)*42' different than 'print 42*(52-80)' in Perl?
本文介绍了为什么 Perl 中的“print (52-80)*42"与“print 42*(52-80)"不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Perl:: 是什么:
Perl:: What is:
1. (52-80)*42
2. 42*(52-80)
答案:
1. -28
2. -1176
为什么?
请享受解释/证明这一点的乐趣!
Have fun explaining/justifying this please!
#!/usr/bin/perl
use strict;
print 42*(52-80) , "
";
print ((52-80)*42) , "
";
print (52-80)*42 , "
";
print "
";
my $i=(52-80)*42;
print $i, "
";
输出:
> -1176
> -1176-28
> -1176
推荐答案
如果添加使用警告;
你会得到:
If you add use warnings;
you'll get:
print (...) interpreted as function at ./test.pl line 5.
Useless use of a constant in void context at ./test.pl line 5
这篇关于为什么 Perl 中的“print (52-80)*42"与“print 42*(52-80)"不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文