-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.
In reply to Re^4: Extracting Data from a second line
by ikegami
in thread Extracting Data from a second line
by RCP
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |