Dr.Ruud wrote:
"Mr. Shawn H. Corey" schreef:
Louise Hoffman:
I would like to replace the first 2 bytes from ## to BM in all the
files in a directory. The files are binary.
Use glob to get the list of files. Use open with read-write to read
the first line and replace the bytes.
I wouldn't read a "line", because the first line could be the whole
file, and the file could be multi-megabyte.
{ local $/ = \2; # process in chunks of 2 bytes
open my $fh, "+<", $filename # read/write
or die $!;
if ( <$fh> eq "##" ) {
seek $fh, 0, SEEK_SET;
print $fh, "BM";
}
}
Or use read() and write().
ITYM read() and print()
OR sysread() and syswrite()
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/