in reply to Question about binary file I/O

perhaps something like this:
$i = 0; $TileData = 0x0000; while(!(eof(IN))) { $BytesRead = read(IN, $TileData, 2); unless($BytesRead != 2) { $NewTileData = (($TileData & pack('S*', 0xFC7F)) | (pack('S*', +$GFXFileBits))); print OUT $NewTileData; $i++; next; } }

you might want to use something other than 'S' (unsigned short) for pack, depending on the format of your data, look at pack and perlpacktut for details.

Replies are listed 'Best First'.
Re^9: Question about binary file I/O
by TheMartianGeek (Acolyte) on Mar 05, 2011 at 07:38 UTC
    Hm...so there's no way to do that without the seek function? This has come up again; here, I need to write characters to a certain position. There isn't some writetowhatever(FILEHANDLE, $variable, NUMCHARS, $offset) function or anything that would make that possible with just one function instead of two or more?
      Check perlfunc if you want. But the standard is to seek and then to write or syswrite. (The difference being whether you want to buffer your requests to write. Usually you do. Really.)
        I think you mean print (buffered by default) or syswrite (unbuffered)? write is not the opposite of read