这个Perl程序哪里错了?1 /usr/bin/perl -w2 use strict;4 if ( $priceInDollars >=100 ) { 6 print "This item is too expensive!\n";7 }8 else {9 print "I can afford this.\n";10 }11 my $priceInDollars = 100;行数别理它,有点乱
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/18 00:59:24
![这个Perl程序哪里错了?1 /usr/bin/perl -w2 use strict;4 if ( $priceInDollars >=100 ) { 6 print](/uploads/image/z/14170740-60-0.jpg?t=%E8%BF%99%E4%B8%AAPerl%E7%A8%8B%E5%BA%8F%E5%93%AA%E9%87%8C%E9%94%99%E4%BA%86%3F1+%2Fusr%2Fbin%2Fperl+-w2+use+strict%3B4+if+%28+%24priceInDollars+%3E%3D100+%29+%7B+6+print+%22This+item+is+too+expensive%21%5Cn%22%3B7+%7D8+else+%7B9+print+%22I+can+afford+this.%5Cn%22%EF%BC%9B10+%EF%BD%9D11+my+%24priceInDollars+%3D+100%3B%E8%A1%8C%E6%95%B0%E5%88%AB%E7%90%86%E5%AE%83%2C%E6%9C%89%E7%82%B9%E4%B9%B1)
这个Perl程序哪里错了?1 /usr/bin/perl -w2 use strict;4 if ( $priceInDollars >=100 ) { 6 print "This item is too expensive!\n";7 }8 else {9 print "I can afford this.\n";10 }11 my $priceInDollars = 100;行数别理它,有点乱
这个Perl程序哪里错了?
1 /usr/bin/perl -w
2 use strict;
4 if ( $priceInDollars >=100 ) {
6 print "This item is too expensive!\n";
7 }
8 else {
9 print "I can afford this.\n";
10 }
11 my $priceInDollars = 100;
行数别理它,有点乱
这个Perl程序哪里错了?1 /usr/bin/perl -w2 use strict;4 if ( $priceInDollars >=100 ) { 6 print "This item is too expensive!\n";7 }8 else {9 print "I can afford this.\n";10 }11 my $priceInDollars = 100;行数别理它,有点乱
如果说错的话,就是第4行的if语句,在对$priceInDollars赋值以前(第11行)就使用了.因此,在if语句中,$priceInDollars的值是undef,实际取值是0,所以4~10行的语句永远输出:I can afford this.