in reply to Re^3: Extracting Data from a second line
in thread Extracting Data from a second line

-s FILE is often too big — not just when using DATA — since read is to be given a number of characters (as opposed to a number of bytes) when binmode isn't set to raw.

open(FILE, $0) or die("Unable to open $0: $!\n"); $read = read(FILE, $buf='', -s FILE); print("Character mode:\n"); print("Bytes requested: ", -s FILE, "\n"); # 580 print("Chars read: ", $read, "\n"); # 560 print("Chars read: ", length($buf), "\n"); # 560 seek(FILE, 0, 0); binmode(FILE); print("\n"); $read = read(FILE, $buf='', -s FILE); print("Bin mode:\n"); print("Bytes requested: ", -s FILE, "\n"); # 580 print("Chars read: ", $read, "\n"); # 580 print("Chars read: ", length($buf), "\n"); # 580

But like you said, it's ok if it's too big.

Replies are listed 'Best First'.
Re^5: Extracting Data from a second line
by kwaping (Priest) on Feb 16, 2006 at 19:25 UTC
      The number returned by that program is still larger than it needs to be in Windows. There are 41 characters to read in Windows, but $size_of_DATA is 44.
        Must be a windows vs. unix issue then. The numbers work out on my system. Also, in your previous code, the numbers were all 560 on my system.