"John W. Krahn" schreef:
> Dr.Ruud:
>>  Mr. Shawn H. Corey:
>>> 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()

Oops yes, thanks for the correction. The "seek" looked like "fseek" only
a few seconds before I hit send, so I wasn't as focussed as I should
have been.

-- 
Affijn, Ruud

"Gewoon is een tijger."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to