Why does the whole process wait for 10 seconds before showing the results in the following code? I was expecting it to show each iteration every 1 second:
my @array = (1..10);
for (reverse(@array)){
print $_, "\t";
sleep 1;
}
print "\n";
Why does the whole process wait for 10 seconds before showing the results in the following code? I was expecting it to show each iteration every 1 second:
my @array = (1..10);
for (reverse(@array)){
print $_, "\t";
sleep 1;
}
print "\n";
You are Suffering from Buffering. Add this before your for loop to flush the output buffer (refer to $OUTPUT_AUTOFLUSH in perlvar):
$| = 1;