Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Oh wise ones,
Here is my dillema, when opening a text file using the 'open' function,
I read in the file into a variable, then print the length of the variable
to screen.
Here are the results(original length=1351):
Windows: length shows 1335
Linux box: length shows 1351

My question is, it seems that running the 'open' function on a windows box strips all the carriage returns
and resulting data is much smaller than original. Is there a way to go around this nasty problem? I try to uuencode the file and it's causing me grieve.
Any help would be appreciated...

Replies are listed 'Best First'.
Re: Issues with files on a windows machine
by ikegami (Patriarch) on Sep 11, 2007 at 20:59 UTC

    The file on your unix box is bad.
    Text files in Windows end with CRLF.
    Text files in unix end with LF.
    You should have:

    Windows file length1351
    Linux file length1335
    Windows var length1335
    Linux var length1335

    If it's not a text file, you should be using binmode on the file handle. That'll prevent the CRLF<->LF conversion.

Re: Issues with files on a windows machine
by moritz (Cardinal) on Sep 11, 2007 at 20:54 UTC
    You should call binmode $filhandle after open and before the first read.
Re: Issues with files on a windows machine
by mr_mischief (Monsignor) on Sep 11, 2007 at 22:57 UTC
Re: Issues with files on a windows machine
by goibhniu (Hermit) on Sep 11, 2007 at 21:28 UTC

    Did data get encoded in transit? E.g., on Windows: '><&'' on Linux: '&gt;&lt;&amp;&quot;'?


    I humbly seek wisdom.