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

Replace 163 with -s DATA.

Replies are listed 'Best First'.
Re^3: Extracting Data from a second line
by kwaping (Priest) on Feb 16, 2006 at 16:34 UTC
    If I'm working with a regular filehandle, I always use -s to get the length to read, but unfortunately that doesn't work here. -s DATA will give you the length of the entire file, Perl code included, not just the part after __DATA__.

    Update: With that stated, I do realize it wouldn't hurt anything to supply a bigger number than required as the third argument to read.

      -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.