in reply to Re^6: Error binmode() on unopened filehandle
in thread Error binmode() on unopened filehandle
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Error binmode() on unopened filehandle
by AnomalousMonk (Archbishop) on May 04, 2020 at 00:38 UTC | |
by Marshall (Canon) on May 07, 2020 at 03:53 UTC | |
|
Re^8: Error binmode() on unopened filehandle
by haukex (Archbishop) on May 03, 2020 at 22:52 UTC | |
by Marshall (Canon) on May 07, 2020 at 04:05 UTC |