我有一个简单的程序
use strict;
use warnings;
print "Enter a number:\n";
my $number1 = <STDIN>;
chomp $number1;
print "Enter another number:\n";
my $number2 = <STDIN>;
chomp $number2;
if ( $number2 == 0 ) {
print "error: cnt divide by zero\n";
}
elsif ( ( $number1 == 0 ) or ( $number2 == 1 )) {
print "$number1\n";
}
else {
my $div = $number1 / $number2;
print "the result is: $div\n";
}
但我不明白为什么打印(输入一个数字并输入另一个数字会显示在 STDIN 之后)。我得到以下输出
[612] perl test.pl
2
0
Enter a number:
Enter another number:
error:cnt divide by zero