Open file in binary mode

B

Bill H

It has been so long since I used Perl to work on a binary file I have
forgotten how to do it. Basically what I need to do is open an
existing file in binary, load every byte of the file starting at the
end and work towards the begining and rewrite it to a new file. In
essense reversing the file. Any tips?


Bill H
 
G

Gunnar Hjalmarsson

Bill said:
It has been so long since I used Perl to work on a binary file I have
forgotten how to do it. Basically what I need to do is open an
existing file in binary, load every byte of the file starting at the
end and work towards the begining and rewrite it to a new file. In
essense reversing the file. Any tips?

open my $f, '<', $file or die $!;
open my $r, '>', $newfile or die $!;
my $data;
while ( read $f, my $buffer, 1024 ) {
$data .= $buffer;
}
binmode $r;
print $r scalar reverse $data;
 
M

Michele Dondi

It has been so long since I used Perl to work on a binary file I have
forgotten how to do it. Basically what I need to do is open an
existing file in binary, load every byte of the file starting at the
end and work towards the begining and rewrite it to a new file. In
essense reversing the file. Any tips?

binmode()

open '<:raw', ...


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top