Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Within each of those 4800 bytes, there's a header (300 bytes), followed by 250 subrecords of 18 bytes each. I need to see the byte values of each of the subrecords. I thought the code would entail something like chopping off the header, recording that, and doing the same with each of the subrecords, which would in turn, get chopped up and recorded. However, I can't seem to figure out a straightforward way to do this. All the stuff I've found is for reading bytes off a filehandle, not from a string, and I know substr is pretty inefficient. Would using regexps be appropriate here? Anybody have thoughts on how to implement this?my ($filename) = shift @_; my ($ref_data) = shift @_; my ($buff, $num_records); open DATA, "<", $filename or die "Cannot open file $filename - + $!\n"; binmode(DATA); while (read(DATA, $buff, 4800)) { #print "$buff\n"; # update ref_data, recording values of data, etc } print "Processed $num_records records in file $filename\n"; close (DATA);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading nested records in binary data
by BrowserUk (Patriarch) on Mar 10, 2006 at 00:59 UTC | |
|
Re: Reading nested records in binary data
by Corion (Patriarch) on Mar 09, 2006 at 22:39 UTC | |
by Anonymous Monk on Mar 09, 2006 at 23:38 UTC | |
by Anonymous Monk on Mar 09, 2006 at 23:25 UTC | |
by duff (Parson) on Mar 10, 2006 at 00:49 UTC | |
by Anonymous Monk on Mar 09, 2006 at 23:08 UTC | |
|
Re: Reading nested records in binary data
by GrandFather (Saint) on Mar 09, 2006 at 22:48 UTC |