Do you know where your variables are? | |
PerlMonks |
Re: Searching a file for an undetermined hexadecimal stringby ChemBoy (Priest) |
on May 13, 2005 at 04:32 UTC ( [id://456602]=note: print w/replies, xml ) | Need Help?? |
The line-processing approach above unfortunately does almost exactly the opposite of what you want, unless I'm tireder than I thought. The problem you're going to have is that you aren't (or at least, you haven't mentioned that you are) reading a record-based file, so no matter what size chunk you read in, unless you read the whole file into a scalar, you run the risk that you'll have a string that begins in one read and ends in another. There are a few ways to deal with this, but for the moment I'm going to pretend you can read the whole file in as a single string, because it will make my life easier. In that case, this should do roughly what you want (and precisely what you specified):
There's almost certainly a better way to do that regex, but I'm reasonably sure that this one will in fact work, however inelegantly. If you can't process the file all at once, then you will have to get creative. I'd think this would work:
Note that it is late and I'm not testing this code, so it is by no means 100% guaranteed not to sneeze demons at you. That said, it really ought to work fine. :-) If God had meant us to fly, he would *never* have given us the railroads. --Michael Flanders
In Section
Seekers of Perl Wisdom
|
|