StrawberryPerl/Perl-Dist-Strawberry

input file streaming - regression between 5.38.0.1 and 5.32.1.1

Closed this issue · 3 comments

Hi,
I have some perl scripts that stream input file and parse it in live.
It worked well until version 5.32.1.1, but it does not work anymore with 5.38.0.1.
I wrote a basic example showing the issue:

#!/usr/bin/perl -w

use strict;
use warnings;
my $IN_STREAM;

open( $IN_STREAM, "<", "file_in.txt" ) or die "Fail to open file_in.txt";

while (1) {
    while ( !($_ = <$IN_STREAM>)) {
        sleep(1);
    }
    print "$_";
}

When I run this script with version version 5.32.1.1, I can see the print each time I update file_in.txt.
But with 5.38.0.1, updates in file_in.txt are NOT detected.

Thanks in advance for your support.

Thanks for the report and the reproducer.

The code works as described under Strawberry Perl 5.32.1.1 and 5.36.1.1 but not 5.38.2.2.

However, this looks to be more general than Strawberry Perl.

It does not work as described under a perlbrewed 5.38 on Ubuntu via WSL2 but does work on 5.36.

So it would seem to be due to a change in perl itself.

Looking at perldelta there is this entry: readline() no longer clears the stream error and eof flags.

Following the instructions in that perldelta entry by adding a clearerr call to the file handle gets things to work as expected. Code is below. It includes a few other modifications but the necessary change is the clearerr() call within the inner loop.

#!/usr/bin/perl -w

use strict;
use warnings;

open( my $IN_STREAM, "<", "file_in.txt" ) or die "Fail to open file_in.txt";

$| = 1;

my $str;
while (1) {
    while ( !($str = <$IN_STREAM>)) {
        $IN_STREAM->clearerr();
        sleep(1);
    }
    print "$str" . ':';
}

works well, thanks a lot !

Thanks for confirming. I'll close the issue now.