> -----Original Message-----
> From: Andrew Stone [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 24, 2002 1:29 PM
> To: [EMAIL PROTECTED]
> Subject: Binary File Pattern Matching
> 
> 
> Hello all,
> 
> I'm having a problem with (I suppose) pattern matching.
> Here's the task: To take binary data from windows(little-endian)
> and convert to Unix(big-endian).  

Well, Perl's pack() and unpack() functions can help with that.

> If the file is all numeric, I don't
> have a problem, but it isn't.  I need to be able to recognize that
> one of the four bytes is non-numeric data (spaces, alpha, 
> punctuation..).
> If one of the four is non-numeric then I don't want to do the byte
> swapping.  Right now if there is character data it gets 
> swapped so 'TEST'
> becomes 'TSET'.  I've been searching the web, but haven't 
> found anything
> that works for me.

This really can't be done. The sequence 'TEST' in the file may be
an ASCII string with the word test. Or, it may be the long integer
1413829460 packed in network (big-endian) order. Or something else
altogether. There is no way to say which it is without knowing
something about the structure of the file.

   $ perl -le 'print pack "N", 1413829460'
   TEST

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to