I also would use read() for reading a binary file.
binmode turns off the CRLF to LF conversion, so if you're not seeing CRLF line endings (not sure how you determined that?) then that means the source file has only LF instead of CRLF line endings.
the Perl source file is written on Windows machine with CRLF line endings.
n_bytes is 13, which is 2 short.
I am a bit perplexed about that.
This:
evidently deletes the <CR> characters.my $data = <<EOF; first second EOF
Update:
use strict; use warnings; open (my $out, '>', "test_endings.txt") or die "$!"; print $out "first\n"; print $out "second\n"; close $out; open (my $in, '<', "test_endings.txt") or die "$!"; binmode $in; my $num_bytes = read ($in, my $buf, 20000); print "bytes read = $num_bytes\n"; ## prints 15 The <CR>'s are there in bin mode
In reply to Re^7: Error binmode() on unopened filehandle
by Marshall
in thread Error binmode() on unopened filehandle
by RedJeep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |