in reply to Re^6: Perl binary file reading
in thread Perl binary file reading
"Read" gives me for some reason a problem with some particular byte - I didn't had the time to isolate it.
Are you sure that binmode is enabled?
Both ...
open my $fh,'<:raw',$filename or die "Could not open $filename: $!"; my $data=do { local $/; <$fh> };
... and ...
open my $fh,'<',$filename or die "Could not open $filename: $!"; binmode $fh; my $data=do { local $/; <$fh> };
... should do the trick. The first one requires a perl with support for I/O layers (introduced somewhere in the 5.8.x series, IIRC), the second one should also work with older perls. And this one is for really ancient perls:
local *FH; open FH,"<$filename" or die "Could not open $filename: $!"; binmode FH; my $data=do { local $/; <FH> };
See also Using ":raw" layer in open() vs. calling binmode() and PerlIO.
Alexander
|
|---|