delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/11/05/08:42:07

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
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: Tue, 5 Nov 2002 14:41:52 +0100 (MET)
From: Mikael Hubsch <mikael DOT hubsch AT tfstech DOT com>
X-Sender: <micke AT spirit DOT dynas DOT se>
To: <cygwin AT cygwin DOT com>
Subject: Perl 5.6.1: Problem with CRLF/LF conversions
Message-ID: <Pine.GSO.4.30.0211051354160.22446-100000@spirit.dynas.se>
MIME-Version: 1.0

I'm trying to port a framework of perl scripts to cygwin. I'm running
cygwin 1.3.14 on WinXP. The problem is that perl seems to assume binmode
whenever I read a file, but text mode when I write to one.

The sample code below shows the problem.
If I write a line to a file with a LF-only ending, perl (or cygwin) adds a
CR. When I later read the same line from the file the CR isn't removed.

Is there some special option I need to set to make perl always assume text
mode unless I explicitly use the binmode command?


#!/usr/bin/perl -w

open(F, "> foobar.txt") || die "Cannot create foobar.txt";
print F "Line1\n";
print F "Line2\n";
close F;

open(F, "< foobar.txt") || die "Cannot open foobar.txt";
while (<F>) {
    s/(.)/sprintf("%02x ", ord($1))/ges;
    print "$_\n";
}
close F;

exit 0;

-- 
 Mikael Hubsch                 Email: Mikael DOT Hubsch AT tfstech DOT com
 TFS Technology AB             Phone: +46-8-7259730
 Box 10020                     Fax:   +46-8-6494970
 S-121 26 STOCKHOLM, SWEDEN




--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019