The problem is not a discrepancy between the size reported by WinXP (via say dir or explorer) and that returned by -s, they will be exactly the same.
The problem is the length of the file as loaded into you code if you do not use binmode.
Without binmode, linefeeds within the file on disk, are translated into carriage return/linefeed pairs (and reverse done on output).
Hence:
open I1, '<:raw', 'zz.pl';; $d1 = do{ local $/; <I1> };; print length $d1;; 6712 open I2, '<', 'zz.pl';; $d2 = do{ local $/; <I2> };; print length $d2;; 6571 !wc -l zz.pl;; 141 zz.pl print unpack 'H*', substr $d1, 0, 100;; 23 21 20 70 65 72 6c 20 2d 73 6c 77 0d 0a 75 73 ... print unpack 'H*', substr $d2, 0, 100;; 23 21 20 70 65 72 6c 20 2d 73 6c 77 0a 75 73 ...
In your example, myfile.pl has 2179 lines.
The solution is to use binmode (or '<:raw' & '>:raw' etc.).
In reply to Re: Filesize (-s) is consistenly reporting too small of size in Win32
by BrowserUk
in thread Filesize (-s) is consistenly reporting too small of size in Win32
by wilsond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |