|
|
 |
 |
 |
 |
Perl Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Open file in binary mode
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
Bill H wrote: > 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; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
On Fri, 01 Jun 2007 04:07:19 -0700, Bill H <b @ts1000.us> wrote: >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 -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
|
 |
 |
 |
 |
|