这个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/05/09 08:54:42
这个Perl程序哪里错了?1 /usr/bin/perl -w2 use strict;4 if ( $priceInDollars >=100 ) { 6 print

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