Sorry here's some example code
#! c:/perl/bin/perl; use strict; use warnings; #======================= # Define VARS # ====================== my $RECORD_SIZE = 40; my $ID = 0; my $size = 20; # Num of Bytes to read from fi +le my $offset = 0; # Offset to file reading. my $MASK = 'H4C3H4b12H4'; my $file = "FileName"; open( FILE, $file ) || die print "Can not open file"; # open file binmode FILE; # Turn on Binary mode # Read Header for the record. while ( sysread( FILE, $data, $size) ){ #Filehandle,str +ing,length,offset my ($flag,$format,$blocks,$source,$no,$time,$type) = unpack $MASK, + $data; print "Header: $flag\n"; print "Header Data:",unpack $MASK, $data; print "\n"; # Check integity of the header. if ( $flag != 1234 ) { die print "Ill formed header. File may be corrupt."; # Read the remainder of the record. $size = ( ( $RECORD_SIZE * $blocks ) - 20 ); sysread( FILE, $data, $size ); #Filehandle,string,length,offset # Debugging stuff to match Hex editor to file to determine what is goi +ng on. my $long = length($data); print "Size of Data portion of record: $long \n"; my $temp = "H" . $long; #print $temp; my $alldata = unpack $temp, $data; print "Data: $alldata\n"; } close FILE;

In reply to Re: Reading Binary file confusion by Anonymous Monk
in thread Reading Binary file confusion 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.