Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Wed, 24 Jul 2002 13:08:50 +0800 From: Greg Matheson To: cygwin AT cygwin DOT com Subject: perl-5.6.1 handling of \n (was: perl & \n Message-ID: <20020724130850.A46852@ms.chinmin.edu.tw> Mail-Followup-To: cygwin AT cygwin DOT com References: <20020719105932 DOT A11717 AT ms DOT chinmin DOT edu DOT tw> <20020722150604 DOT A85877 AT ms DOT chinmin DOT edu DOT tw> <20020723140301 DOT B44140 AT ms DOT chinmin DOT edu DOT tw> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20020723140301.B44140@ms.chinmin.edu.tw>; from lang@ms.chinmin.edu.tw on Tue, Jul 23, 2002 at 14:03:01 +0800 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 ( ) { $string .= $_; } print "Discipline: $discipline\tString length: @{[length($string)]}\tFile size: @{[-s qq(${mode}file$fileext)]}\n"; close I; } } } Here are my mounts: lang AT 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 -- 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/