Errornous read/sysread for PC-Perl? 
Author Message
 Errornous read/sysread for PC-Perl?

to do a binary read to a file, I use read or sysread on a PC / Perl32
like the procedure down there.

The errornous problem is:

Assume file length of 220 bytes as input.
The result (depending on the blocklength) is _less_ than 220!!

for example: a text file of 216 result 209 bytes!
             a binary file 1210 Bytes, result 267 bytes!!!!!

To compare it, I tried on Macintosh with Per 4.036: excellent and
errorfree

What switch, What special $sign varables have to be set in special
manner?

Any ideas out there?

Thank You for reading an thinking about this problem

Michael

Code follows:
#Start of code example

#!perl
# just to check sysread or read
# count ByteBlocks of a file and display

#init all $var
$lenByte = 2;                # length of block read from the file
$z =0;                       # counter of blocks read

for (;;) {
 $a = read (INFILE, $bb, $lenByte);
# may be also
# $a = sysread (INFILE, $bb, $lenByte);
 $z++;                       # set counter up
 if ($a != $lenByte) {       # Read error?
  last                       # break out of loop
 };

Quote:
}

$totalread = $z * $lenByte + $a;
print ("$lenByte Bytes Blocklength \n"); # results
print ("$z Blocks read, in the last Block $a\n");
print ("Read $totalread Bytes\n");

close (INFILE);

#end of code example

Version of Perl:

Quote:
> This is perl, version 5.001

>         Unofficial patchlevel 1m.

> Copyright 1987-1994, Larry Wall
> Win32 port Copyright (c) 1995 Microsoft Corporation. All rights reserved.
>         Developed by hip communications inc., http://www.*-*-*.com/

>         Perl for Win32 Build 110


--
Hochschule Bremen                 Labor fuer Hochspannungstechnik
Prof. Dr. Michael Hartje        Neustadtswall 30;    28199 Bremen
Telefon: +49 421 5905-444                   FAX: +49 421 5905-476



Tue, 07 Dec 1999 03:00:00 GMT  
 Errornous read/sysread for PC-Perl?



Quote:
>to do a binary read to a file, I use read or sysread on a PC / Perl32
>like the procedure down there.

>The errornous problem is:

>Assume file length of 220 bytes as input.
>The result (depending on the blocklength) is _less_ than 220!!

>for example: a text file of 216 result 209 bytes!
>             a binary file 1210 Bytes, result 267 bytes!!!!!

You might want to do

  binmode (INFILE);

before reading from it as that will stop end of line translations and ^Z
being interpreted as end of file.

Hope this helps,

Mike

--

http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41



Tue, 07 Dec 1999 03:00:00 GMT  
 Errornous read/sysread for PC-Perl?

Hello Mike,

Quote:

> You might want to do

>   binmode (INFILE);

> Hope this helps,

> Mike

Yes indeed, this helped a lot!!!!!!!

Thank You very very very much -- it saved a lot of time and thinking
"how stupid is..."

I was working on a procedure to read TEKTRONIX Waveform data files with
perl and putting it with some additional parameters together for input
to GNUPLOT. Now this works. Great!

I have been asked by TEKTRONIX to publish my work after finishing. It
will be done next.

Michael

--
Hochschule Bremen                 Labor fuer Hochspannungstechnik
Prof. Dr. Michael Hartje        Neustadtswall 30;    28199 Bremen
Telefon: +49 421 5905-444                   FAX: +49 421 5905-476



Tue, 07 Dec 1999 03:00:00 GMT  
 Errornous read/sysread for PC-Perl?

Quote:

> You might want to do

>   binmode (INFILE);

> Hope this helps,

> Mike

Yes indeed, this helped a lot!!!!!!!

I was working on a procedure to read TEKTRONIX scope Waveform data files
with perl and putting it with some additional parameters together for
input to GNUPLOT. Now this works. Great!

I have been asked by TEKTRONIX to publish my work after finishing even
to promote the use of perl for this application. It will be done next.

Michael

--
Hochschule Bremen                 Labor fuer Hochspannungstechnik
Prof. Dr. Michael Hartje        Neustadtswall 30;    28199 Bremen
Telefon: +49 421 5905-444                   FAX: +49 421 5905-476



Tue, 07 Dec 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem reading a telnet connection with sysread/read

2. read() vs. sysread()

3. reading form <> and sysread

4. read, write and sysread, syswrite?

5. tell with read/seek or with sysread/syseek

6. bug in win95 read/sysread?

7. read() vs sysread() in Socket Library

8. read() vs. sysread()

9. Sysread vs Read/Syswrite vs Write

10. read v sysread

11. Reading data from STDIN (using sysread) while running the MainLoop

12. Reading IBM PC io address space

 

 
Powered by phpBB® Forum Software