This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
RE: Perl, text files, & \r
- To: "Cygwin Maillist" <cygwin at cygwin dot com>
- Subject: RE: Perl, text files, & \r
- From: "Christopher Rath" <christopher at rath dot ca>
- Date: Sat, 7 Jul 2001 23:13:47 -0400
- Cc: "Max Bowsher" <max at bowshernet dot freeserve dot co dot uk>
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@rath.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@bowshernet.freeserve.co.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/