in reply to Filesize (-s) is consistenly reporting too small of size in Win32

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


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Filesize (-s) is consistenly reporting too small of size in Win32
by wilsond (Scribe) on Jan 17, 2009 at 10:55 UTC

    My file has 788 lines, including the final blank line in the file.

        I rebooted my WinXP box and now everything looks fine. **ARGH** I hate Windows. Why would a reboot fix it? I don't know what the problem was at all. It was consistently failing, now it's consistently not failing. In any case, I appreciate your help.


        Nature is not cruel, pitiless, indifferent. This is one of the hardest lessons for humans to learn. We cannot admit that things might be neither good nor evil, neither cruel nor kind, but simply callous — indifferent to all suffering, lacking all purpose.
        - Richard Dawkins

        Just a thought... "dir" in Windows doesn't cache, does it? That's the only possible thing I can think of. I was careful to be sure that I was testing against the same filename in "dir" and "-s".


        Nature is not cruel, pitiless, indifferent. This is one of the hardest lessons for humans to learn. We cannot admit that things might be neither good nor evil, neither cruel nor kind, but simply callous — indifferent to all suffering, lacking all purpose.
        - Richard Dawkins