delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/07/07/23:14:30

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
From: "Christopher Rath" <christopher AT rath DOT ca>
To: "Cygwin Maillist" <cygwin AT cygwin DOT com>
Cc: "Max Bowsher" <max AT bowshernet DOT freeserve DOT co DOT uk>
Subject: RE: Perl, text files, & \r
Date: Sat, 7 Jul 2001 23:13:47 -0400
Message-ID: <PAEBIDDBILOFFDPNDLKNOEODCDAA.christopher@rath.ca>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000
In-Reply-To: <012a01c1072c$a263f5e0$83fafea9@tiny450>

Max, thanks for the pointer.  While your specific thought isn't
correct---that Perl somehow translates "\n" when dealing with $\ or
$/---double checking my understanding did cause me to stumble upon the
solution: use of the 'binmode' command.

If I modify my code as follows, it will work under both UNIX and
Windows/MS-DOS:
Instead of
	while(<>) {
		# do some funky stuff
		print $_;
	}
Write:
	binmode ARGV;
	while(<>) {
		# do some funky stuff
		print $_;
	}
and all will be well.

I think this should be in the Cygwin FAQ.  Why this works can be found on
pp. 53-55 and 147 of "Programming Perl 2nd Ed.".

Cheers,
Christopher
=========== Christopher Rath == (613) 824-4584 ===========
       1371 Major Rd., Orleans, ON, Canada  K1E 1H3
=============== mailto:christopher AT rath DOT ca ===============
  ``Hydrogen is a colourless, odourless gas which, given
  enough time, turns into people.'' --- Henry Hiebert
================== http://www.rath.ca/ ===================

-----Original Message-----
From: Max Bowsher [mailto:max AT bowshernet DOT freeserve DOT co DOT uk]
Sent: 7 July, 2001 17:35
To: Cygwin Maillist
Subject: Re: Perl, text files, & \r

> I've tried forcing $\ to "\n", but that didn't help.
Read the perl docs! "\n" in a $\ or $/ context is automagically translated
into the default system line ending by perl. Using an octal code should
avoid this, I think.

Max.


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