in reply to sysread() is deprecated on :utf8 handles
It makes no sense to use sysread on a file handle with the :utf8 layer because the read might have ended mid-character.
sysread-using code should look something like this:
binmode($fh); # Or open with :raw my $buf = ''; while (1) { # Or this could be a select loop. my $rv = sysread($fh, $buf, BLOCK_SIZE, length($buf); die($!) if !defined($rv); last if !$rv; # Identify and extract message. # Using LF-terminated messages in this example. while (s/^([^\n]*)\n//) { my $msg = $1; process_message($msg); } } die("Premature EOF") if length($buf);
In your case, you just want to blindly forward everything you receive, so simply avoid decoding or encoding!
binmode($fh_in); # Or open with :raw binmode($fh_out); # Or open with :raw while (1) { # Or this could be a select loop. my $rv = sysread($fh, my $buf, BLOCK_SIZE, length($buf); die($!) if !defined($rv); last if !$rv; print($fh_out $buf); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: sysread() is deprecated on :utf8 handles
by mje (Curate) on Jul 21, 2017 at 07:54 UTC |
In Section
Seekers of Perl Wisdom