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);
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|