This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

perl-5.8.0 and \n


I tried to run my perl script checking 5.6.0's treatment of
binary and text mode mounts on a Windows 2000 machine, but had
trouble with mount, and I gave up.

With the new 5.8.0, IO has layers and old programs writing to
files on binary mode mounts will be broken by the new default
crlf layer for Win32-like systems (which includes cygwin)
unless they also specified binmode.

I tried using the open pragma,

        use open IO  => $layer;

to set the default layer, but although the pragma is supposed to
be lexically scoped, I couldn't change the default within a foreach loop. 

So I set the PERLIO environmental variable and ran this script on
Windows 98 and Windows 2000:

#!/usr/bin/perl -w

foreach my $modefile ( '/binary/file', '/text/file' )
{
        my $string = '';
        open O, ">$modefile" or die $!;
        print O "123\n567\n"; 
        close O;
        open I, $modefile or die;
        while ( <I> ) { $string .= $_; } 
        print "\t\tString: @{[length($string)]}   File: @{[-s $modefile]}";
        close I;                                      
        unlink $modefile;
}

These are the results:

                Underlying binary mode          Underlying text mode
PERLIO=raw	String: 8   File: 8             String: 8   File: 8
PERLIO=unix	String: 8   File: 8             String: 8   File: 8
PERLIO=stdio	String: 8   File: 8             String: 10   File: 10
PERLIO=perlio	String: 8   File: 8             String: 8   File: 8
PERLIO=crlf	String: 8   File: 10            String: 8   File: 10

It seems 5.8.0 is nullifying the distinction between binary and
text mounts. Only stdio, the original C library, gives different
results for the 2 modes.

I think I am coming round to the MS idea that writing CRs to text
files is "natural" :-)

This way, porting from Unix perl programs is easier, at least if
you are running 5.8.0. No binmodes sprinkled through files.

-- 
Greg Matheson               Learn a third language and 
Chinmin College             be born again, again.
                       
Taiwan Penpals Archive <URL: http://netcity.hinet.net/kurage>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]