"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().
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/