Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I need to be able to open a file in binary mode, then search for a specific string of hexadecimal numbers and replace each character with the hexadecimal character 00. The problem I have is that the string I'm searching for will vary in length and content. Each string will start with the same characters (31,33,39,37) and end with the same character (00). However, each string will contain different characters between the beginning (31,33,39,37) and end (00) as well as being different lengths. This is what the code looks like right now:
binmode STDIN; binmode STDOUT; $/ = '1397'; while (<>) { s/1397$/\0\0\0\0/; print; }
How can I tell the program to start replacing characters when it encounters 1397 and then stop replacing characters when it encounters a 0? Is there some sort of wildcard character that I can use that will replace every character it encounters?

Thanks.

In reply to Searching a file for an undetermined hexadecimal string by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2023-02-06 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?