Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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.


Comment on Re: Question about binary file I/O
Download Code
Re^9: Question about binary file I/O
by TheMartianGeek (Novice) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://886463]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-25 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls