Right now I noticed that if you write

use strict; use warnings; foreach my $value (10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 'БУМ...'){ print $value; sleep(1); } 

That program waits when 11 seconds pass and displays all the contents. And if you change

 use strict; use warnings; foreach my $value (10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 'БУМ...'){ print $value, "\n"; sleep(1); } 

Then everything is fine (every second the figure is displayed). So why in the first case, the text is stored in the "buffer", and in the second immediately displayed? Indeed, in fact, there is no difference between them ...

  • In general, the weather makes a line break \n , as I understand it. - Error
  • @alexlz, oh, good old autoflush! Caused nostalgia for the old days. - northerner

1 answer 1

And if so?

 #!/usr/bin/perl -w use strict; use warnings; $|=1; foreach my $value (10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 'БУМ...'){ print $value; sleep(1); } 
  • I know about this, the question is why when adding / \ n output to the stream occurs immediately - Error
  • one
    This is called line buffering. - alexlz