This is the mail archive of the cygwin@sources.redhat.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]

Re: Perl bug with DOS file line endings?


>>>>> "Ian" == Ian Puleston <ian@underpressuredivers.com> writes:
  Ian> Perl 5.6.1-1 seems to get confused as to whether its processing a DOS or
  Ian> Unix format file, depending on what shell it is run under. I'm using it in
  Ian> Windows 2000 to process a DOS format source file with line endings 0D0A
  Ian> (\r\n):

  Ian> When it is run directly from a DOS command prompt it works as expected and
  Ian> produces an output file with line endings 0D0A.

  Ian> When it is run from either bash or make initiated from a DOS command prompt,
  Ian> then it produces an output file with line endings 0D0D0A (\r\r\n). It seems
  Ian> that in this case it thinks that it is processing a Unix file, and has added
  Ian> a 0D to change from the Unix 0A line ending to the DOS 0D0A.

  Ian> I'm using CygWin make 3.79-3 and bash 2.04-5.

I'm having problems in this area also.  It seems like I get better
results if I set the input record separator ($/) to "\r\n", if the OS
is "cygwin" (the "$^O" variable).  However, it still doesn't seem to
fix everything.

I have the following little test case:

------------
#! /usr/local/bin/perl -w
if ($^O =~ /cygwin/)
{ $/ = "\r\n"; }

my $stuff = `echo abc`;
print ::stderr "stuff[" . $stuff . "]\n";
if ($stuff =~ /$\//)
{ print ::stderr "Found IRS in string.\n"; }

my $chompNum    = chomp $stuff;
print ::stderr "stuff[" . $stuff . "] chompNum[" . $chompNum . "]\n";
chop $stuff;
print ::stderr "stuff[" . $stuff . "]\n";
------------

On Solaris (with perl 5.005_03), I get the following (reasonable)
output:

--------------
stuff[abc
]
Found IRS in string.
stuff[abc] chompNum[1]
stuff[ab]
--------------

On NT/Cygwin, (with perl 5.6.1), I get the following (confusing)
output:

------------
stuff[abc
]
stuff[abc
] chompNum[0]
stuff[abc]
------------

When I send the output to a file and use "od -c" to view the output,
on NT, I see "\r \n" for each line ending.

This is probably another "binmode/textmode" issue, but I don't
understand it.

-- 
===================================================================
David M. Karr     ; w:(425)487-8312     ; TCSI & Best Consulting
dkarr@tcsi.com    ; Java/Unix/XML/C++/X ; BrainBench CJ12P (#12004)


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]