这个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/11/26 13:35:50
这个Perl程序哪里错了?1/usr/bin/perl-w2usestrict;4if($priceInDollars>=100){6print"Thisitemistooexpensive!\n";

这个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.