为什么print命令在STDIN之后执行,虽然之前调用它?

时间:2012-11-02 14:14:06

标签: perl

我有一个简单的程序

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之后输入一个数字并输入另一个数字).i得到以下输出

[612] perl test.pl
2
0
Enter a number:
Enter another number:
error:cnt divide by zero

1 个答案:

答案 0 :(得分:1)

程序开头的

$| = 1