Andre Warnier wrote:
> Message text written by "$Bill Luebkert"
> 
> Andre Warnier wrote:
> 
>>Purely for intellectual curiosity, if anyone feels like takeing the time
> 
> :
> 
>>Is there any point in saying "binmode FH;" if FH is an output file handle
> 
> ?
> 
> Of course - if you're writing binary data (like a GIF, JPEG, etc).
> I even use it on text files since I want my local files to have UNIX
> line endings instead of Windoze.
> <
> 
> But, I don't understand.
> 
> If one is writing binary data, one would use something like
> 
>         print FH $buffer;
> 
> To myknowledge, Perl then writes whatever bytes are in $buffer, and does
> not add anything at the end of it
> (printing "$buffer\n" would be another story).
> 
> So, if one is writing only the bytes present in $buffer, what difference
> does it make wether one says "binmode FH" or not ?

What about the 0x0A'a (LF's or \n's) that are embedded in the binary data ?
Do you think that binary data does not contain linefeeds (not intended as
linfeeds, but linefeeds none-the-less) ?  A binary byte containing the value
10 would appear as a LF/\n.

> My understanding of the difference between Unix and Windows line endings is
> as follows :
> 
> 1)
> - For text files, Unix programs (libraries ?), by convention,  understand a
> line ending as being composed of a single "LF" character.
> - Windows (libraries) on the other hand, by convention, expect a "CR/LF"
> pair as a line ending.

True, but Win32 will mostly work fine without the CR.

> 2)
> - When writing a text file in Perl under Unix, if one writes "xyz\n", Perl
> tries to do "the right thing" under that platform, and converts the "\n" in
> a single LF.
> - When writing a text file in Perl under Windows, if one writes "xyz\n",
> Perl tries to do "the right thing" under that platform, and converts the
> "\n" in a CRLF pair.

True.

> This last, it would also do under Windows, if one beforehand said "binmode
> FH" for the output filehandle.  The difference is in writing "\n" or not,
> not in the "binmode".
> 
> Not so ?

I didn't follow that last paragraph.  On Win32 \n(LF) is converted to \r\n(CRLF)
unless binmode is in effect - in which case \n will generate just a LF.

> When I , under Perl under Unix, write a text file which I want to be
> readable without conversion by a Windows program, I write it as :
> 
>         print FH "$Line\r\n";
> 
> without specifying binmode FH, and it works fine.

binmode is a no-op on UNIX, so that would make sense to add the CR.

> If I said the following :
> 
>         binmode FH;
>         print FH "$Line\n";
> 
> would it then automatically translate the "\n" into CRLF ?

No - you have binmode set, so on Win32, the \n would not be converted to CRLF.
ON UNIX binmode means nothing - so same result.

-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=162126130
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to