learningMatlab
learningMatlab

Reputation: 229

why does the print command execute after the STDIN although called before it?

I have a simple program

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";
}

but i do not understand why the print(enter a number and enter another number is displayed after the STDIN).i get the following output

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

Upvotes: 2

Views: 238

Answers (1)

snoofkin
snoofkin

Reputation: 8895

$| = 1 at the beginning of the program

Upvotes: 1

Related Questions