in reply to how to read binary file and give a binary output?
It's better if you can work out how to do this on your own by reading the sources mentioned above. Here is some example code, although much of it may still be confusing without doing some additional reading:
# Set the input and output filenames my $ifilename = 'file.in'; my $ofilename = $ifilename . '.bin'; # Open the files and ensure we handle them as binary data open my $ifile, '<', $ifilename or die "could not open input file $!"; open my $ofile, '>', $ofilename or die "could not open output file $!" +; binmode $ifile; binmode $ofile; # Read the binary data $_ = do { local $/; <$ifile> }; # Replace the initial bytes with zero s/^(.*?)(\x4F\xFF)/"\x0" x length($1) . $2/se; # Store the result in the output file print $ofile $_; # Tidy up close $ifile; close $ofile;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to read binary file and give a binary output?
by mr_mischief (Monsignor) on Oct 16, 2014 at 17:46 UTC | |
by Loops (Curate) on Oct 17, 2014 at 03:14 UTC |