Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I am having trouble understanding exactly what kind of data that you really have. This matters. Do you have real binary? Or are you using some textual string representation of binary data?
AnomalousMonk immediately converted your string into "real binary", which is not unreasonable as you can't post a binary file here, you'd have to uuencode it or whatever. It could be that you are working from a spec and don't have a real binary file to work from. Below shows to write one to disk for testing. Yes, there are a number of ways to write the code that gets the length: so questions: 1. Do you really have real binary or are you just working from this "nibblelist" format in ASCII? 2. It would be helpful if you had a little chart explaining or the C record declaration or equivalent in whatever format you can: After see they single byte of type and the 2 bytes (little endian) of length, then there are 3 different types of data sections that can follow depending upon the type, please explain that a bit more - not sure that I really get it. I would suggest reading more about substr. I think you probably want to leave off REPLACEMENT parm. The $str = substr eXPR, OFFSET, LENGTH, REPLACEMENT If you really want to read binary, read more about read as you will have to set binmode and also pay attention to the return value of read which is the actual number of bytes read. All of this is different if you just have an ASCII representation of binary instead of "real binary". In reply to Re^3: How to sort record using pack function ?
by Marshall
|
|