Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^15: Question about binary file I/O

by TheMartianGeek (Novice)
on Mar 05, 2011 at 22:11 UTC ( [id://891604]=note: print w/replies, xml ) Need Help??


in reply to Re^14: Question about binary file I/O
in thread Question about binary file I/O

Actually, that's a good idea. The problem with that, though, is that the print function completely erases the rest of the file. Now that I think about it, I don't know if I ever found a good way to overwrite characters in a file without erasing the rest of the file...

Replies are listed 'Best First'.
Re^16: Question about binary file I/O
by BrowserUk (Patriarch) on Mar 05, 2011 at 23:17 UTC
    The problem with that, though, is that the print function completely erases the rest of the file.

    It won't if you use the right open mode; ie. '+<':

    #! perl -sw use strict; ## Open for reading and writing open IO, '+<', 'junk.dat' or die $!; seek IO, 11, 0; print IO 'this overwrites'; close IO; __END__ C:\test>type junk.dat xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx C:\test>junk59 C:\test>type junk.dat xxxxxxxxx this overwritesxxxxx xxxxxxxxx

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Oh, I see. That's useful.

      Okay, my next question is kind of hard to describe...basically, I want to find all blocks of data in a file that are composed of a single specified character and have a specified minimum length. (Say, all blocks of character 0x20 that are at least 12 bytes long.) BUT, said blocks a) shouldn't cross certain boundaries (say, they shouldn't overlap between groups of 1000 bytes) and b) shouldn't be taken into account if they are part of a reserved block marked with a certain keyword (say, the ASCII characters "U S E D" followed by the block length). I don't really even know where to start on this...
        I don't really even know where to start on this...

        A new SoPW. And a much clearer description of

        1. The contents of the file and its formatting.

          With preferably an example of the data that contains typical contents and at least 3 records that match. If that means it would be too big to post here, then making an example available off-site shouldn't be too hard.

        2. What you are actually searching for.

          Ie. less "(Say, all blocks of character 0x20 that are at least 12 bytes long)" & "say, they shouldn't overlap between groups of 1000 byte" & "(say, the ASCII characters "U S E D" followed by the block length)".

        3. And what you want to do once you've found them.

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-19 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found