I quote from perlfaq5:-

How do I randomly update a binary file?
If you're just trying to patch a binary, in many cases something as simple
as this works:

    perl -i -pe 's{window manager}{window mangler}g' /usr/bin/emacs
However, if you have fixed sized records, then you might do something more
like this:

    $RECSIZE = 220; # size of record, in bytes
    $recno   = 37;  # which record to update
    open(FH, "+<somewhere") || die "can't update somewhere: $!";
    seek(FH, $recno * $RECSIZE, 0);
    read(FH, $record, $RECSIZE) == $RECSIZE || die "can't read record
$recno: $!";
    # munge the record
    seek(FH, -$RECSIZE, 1);
    print FH $record;
    close FH;
Locking and error checking are left as an exercise for the reader. Don't
forget them or you'll be quite sorry.

==================
This might give you a beginning
- Roger -
----- Original Message -----
From: "Connie Chan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, December 30, 2001 5:51 PM
Subject: I need some concepts about binmode


Yet..... I still don't know how to handle binary data with perl......
I just made a text file with Pascal... It sound read write are quite
easy...... but in perl... I have read some examples..... it is require
for use binmode(MYFILE) ; then the read is require something
say as buffer size... What are they actually ? Would anybody tell
me how to handle binary data ?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to