in reply to Need help understanding some code ...
If $actually_read == $max_buf_size that could mean that there is more left to be read. Also anything that doesn't have actual data in, is "unknown" (not necessarily what Perl calls undef) because there could be some previous value in $temp? So if you are going to process input data like this, attention needs to be paid to what is actually in the $buffer (number of bytes), not the max size that you intend to allow for this read.
I also don't see anything that would lead me to believe that you are reading anything but ASCII or unicode representable text in which case more common Perl string reads would be more appropriate. If these strings end in NUL, you can define $/=0; (input record separator instead of default of \n). Also, like others, I don't see how this code works for any more than one pair.
If you could put a short line into a test file, text.txt and then run this small script, we would see what is really in there:
#!/usr/bin/perl -w use strict; my $buf; open (IN, "test.txt") || die "can't open test.txt"; binmode (IN); my $actual = read (IN, $buf, 2048); foreach my $i (0..$actual-1) { printf "%02X ", ord(substr($buf,$i,1)); }
|
|---|