SPUG: Not reading to end of binary file on the PC

Tim Buckwalter TimBuckwalter at aol.com
Mon May 7 13:31:13 CDT 2001


I've also had problems on Windows machines with data containing \x1A -- that's a
Ctrl-Z or EOF marker. Sorry, I can't remember how I fixed or avoided this
problem: I normaly process only text data so I don't open files in binmode or
use other than \n as the default input record delimiter. But I always strip out
\x1A from text just to be safe. I remember discovering this problem outside of
Perl: I was using "cat" to concatenate a bunch of files and the output file
didn't add up. One of the files had an embedded \x1A and "cat" was reading that
as an EOF marker.

Tim Buckwalter
Senior Language Engineer
AOL Mobile (formerly Tegic)
1000 Dexter Ave N, Suite 300
Seattle, WA 98109-3574
206.268.7552 phone
206.343.7004 fax
206.343.7001 front desk
TimBuckwalter at aol.com
www.tegic.com

"Cheryl Tornquist (Seattle)" wrote:

> Hi all,
>
> I have a chance to prove the usefulness of PERL in my new company, but I'm
> stumped on a problem and hope someone else may know the answer.  I've
> written several successful PERL scripts for other companies but cannot find
> anything to solve this one in the Camel book, the O'reilly cookbook,
> Learning Perl on Win32, Perl for System Administration, the online docs or
> several other sources.  I'm already using binmode.
>
> The script reads a proprietary binary file and gets different results
> between a sun/solaris environment (PERL ver. 5.6.0) and Windows 2000
> environment (ActiveState build 522 and build 623).  The code works perfectly
> on the Unix box (reads in all the file and formats it to a text file) but
> only part of the binary log file is read when using Win2000 (the required
> OS).  A section of relevant pseudo code is below.  When running on the PC,
> the script reads the 12 fixed bytes until the last line which returns only
> 11 bytes.  This is when it encounts the hex code 001a 4e00 for the first
> time on all three sample files.  001a are the 11th and 12 bytes.  read()
> returns up to and including the first 00 (ASCII NULL) but doesn't read the
> 1a as it should (ASCII substitute -- what does a substitute do?).
>
> What is happening here and how do I get the script to read the whole file on
> the Windows platform?
>
> Help is greatly appreciated.
>
> Cheryl Tornquist
> Oracle Developer
> Dotcast, Inc.
>
> #!/usr/bin/perl
> open (LOGENTRY, "< $binlog") or die "Can't open file $binlog -- $!.\n";
> binmode (LOGENTRY);
> $template = "H8 B32 B16 B16";
> undef $/;
> while (read LOGENTRY, $logentry, 12) {   # read in the whole file and
> process
>    unpack
>    read the rest of the entry
>    write to text file
> }
> close LOGENTRY;
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>   Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list