Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Question about binary file I/O

by james2vegas (Chaplain)
on Feb 06, 2011 at 00:37 UTC ( #886463=note: print w/replies, xml ) Need Help??

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 (Novice) on Mar 05, 2011 at 07:38 UTC 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://886463]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2018-03-18 14:16 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (230 votes). Check out past polls.