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.6.1 handling of \n (was: perl & \n


Ignore my results from yesterday on how perl handles \n in text
and binary mode files. The results were wrong. Here is a more
sophisticated script to determine the effects of file extension
and the underlying mode of the mount on default and forced
binary and text mode opens in perl-5.6.1.

The script:
#!/usr/bin/perl

use strict;
use Fcntl;

foreach my $mode ( qq(/binary/), qq(/text/) )
{
        print "\nFor underlying $mode mount mode\n";
        foreach my $fileext ( qq(.txt), qq() )
        {
                print "In ${mode}file$fileext\n";
                foreach my $discipline ( 'default', 'binary', 'text' )
                {
                        my $string = '';
                        unlink qq(${mode}file$fileext);
                        sysopen(O, qq(${mode}file$fileext),
					O_WRONLY|O_CREAT|O_TEXT) or die 
						if $discipline eq 'text';
                        open O, qq(>${mode}file$fileext)
                                or die if ( $discipline =~ m/default|binary/ );
                        binmode O, ':raw' or die if $discipline eq 'binary';

                        print O "123\n567\n"; close O;

                        print O "123\n567\n"; close O;
                        open I, qq(${mode}file$fileext);
                        while ( <I> ) { $string .= $_; }
                        print
"Discipline: $discipline\tString length: @{[length($string)]}\tFile size: @{[-s qq(${mode}file$fileext)]}\n";
                        close I;
                }
        }
}

Here are my mounts:
lang@C-34 ~/mb
$ mount
C:\cygwin\bin on /usr/bin type system (textmode)
C:\cygwin\lib on /usr/lib type system (textmode)
C:\tmp\binary on /binary type system (binmode)
C:\tmp\text on /text type system (textmode)
C:\cygwin on / type system (textmode)
c: on /cygdrive/c type user (textmode,noumount)

Here are the results:

For underlying /binary/ mount mode
In /binary/file.txt
Discipline: default     String length: 8        File size: 8
Discipline: binary      String length: 8        File size: 8
Discipline: text        String length: 10       File size: 10
In /binary/file
Discipline: default     String length: 8        File size: 8
Discipline: binary      String length: 8        File size: 8
Discipline: text        String length: 10       File size: 10

For underlying /text/ mount mode
In /text/file.txt
Discipline: default     String length: 10       File size: 10
Discipline: binary      String length: 8        File size: 8
Discipline: text        String length: 10       File size: 10
In /text/file
Discipline: default     String length: 10       File size: 10
Discipline: binary      String length: 8        File size: 8
Discipline: text        String length: 10       File size: 10

The conclusion:
In 5.6.1, the behavior is transparent. If you want to take a Unix
view of things and use an underlying binary mode or force it into
binary mode, it acts like Unix. If you want to go with the
Win32 way of things, you can do that too. In either case, -s
'file' returns the same value as length $string. The file
extension doesn't have any effect.

-- 
Greg Matheson                The teacher as the monkey in the works.
Chinmin College              Intervention without understanding.
                                 
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]