public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Cygwin 1.3.2-1 Problems with CR/LF in Perl
@ 2001-08-22  5:39 Walker, Gavin (CMIS, ANU - Acton)
  2001-08-22  8:33 ` Charles Wilson
  0 siblings, 1 reply; 7+ messages in thread
From: Walker, Gavin (CMIS, ANU - Acton) @ 2001-08-22  5:39 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

Hi,
   I've been trying to write a perl script to edit a text file.  The cut
down version of it is a little further down.  It's pretty simple, read a
file in and dump it out.  My problem is that successive runs creates a
string of CR on each
line.  Every time I run it another CR is added.  To get rid of them I have
to use chomp, then chop and append my own \n.  Perl appears to be reading
the CR/LF characters separately and then out as CR/CR/LF.  This is supposed
to work on unix as well so I can't go chopping unnecessarily.  Running the
same program under DOS (probably using windows' perl) doesn't cause any
problems.  Perl version is 5.6.1 for cygwin.  On installation I told cygwin
to use Dos text format (cvs handles the dos/unix interchange).

Gavin Walker
Canberra, Australia

#!perl -w
use strict;

rename("file2","file1");
open(F1,"file1");
open(F2,">file2");
while(<F1>) {
    # have to use chomp; chop; print F2 $_ . "\n"; to get it to work
    print F2;
}
close(F1);
close(F2);

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin 1.3.2-1 Problems with CR/LF in Perl
  2001-08-22  5:39 Cygwin 1.3.2-1 Problems with CR/LF in Perl Walker, Gavin (CMIS, ANU - Acton)
@ 2001-08-22  8:33 ` Charles Wilson
  2001-08-22  9:34   ` Gerrit P. Haase
  0 siblings, 1 reply; 7+ messages in thread
From: Charles Wilson @ 2001-08-22  8:33 UTC (permalink / raw)
  To: Walker, Gavin (CMIS, ANU - Acton); +Cc: 'cygwin@cygwin.com'

Go to the cygwin-apps mailing list archives and look at the last few 
days.  Hopefully there is a new perl coming soon that addresses your 
problems; it should be available as a test version in the next few days. 
  Once it is, PLEASE test it, Gavin.  None of "us" use text mounts...

--Chuck


Walker, Gavin (CMIS, ANU - Acton) wrote:

> Hi,
>    I've been trying to write a perl script to edit a text file.  The cut
> down version of it is a little further down.  It's pretty simple, read a
> file in and dump it out.  My problem is that successive runs creates a
> string of CR on each
> line.  Every time I run it another CR is added.  To get rid of them I have
> to use chomp, then chop and append my own \n.  Perl appears to be reading
> the CR/LF characters separately and then out as CR/CR/LF.  This is supposed
> to work on unix as well so I can't go chopping unnecessarily.  Running the
> same program under DOS (probably using windows' perl) doesn't cause any
> problems.  Perl version is 5.6.1 for cygwin.  On installation I told cygwin
> to use Dos text format (cvs handles the dos/unix interchange).
> 
> Gavin Walker
> Canberra, Australia
> 
> #!perl -w
> use strict;
> 
> rename("file2","file1");
> open(F1,"file1");
> open(F2,">file2");
> while(<F1>) {
>     # have to use chomp; chop; print F2 $_ . "\n"; to get it to work
>     print F2;
> }
> close(F1);
> close(F2);




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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin 1.3.2-1 Problems with CR/LF in Perl
  2001-08-22  8:33 ` Charles Wilson
@ 2001-08-22  9:34   ` Gerrit P. Haase
  0 siblings, 0 replies; 7+ messages in thread
From: Gerrit P. Haase @ 2001-08-22  9:34 UTC (permalink / raw)
  To: cygwin

> Charles Wilson schrieb am 2001-08-22 11:33:

> Go to the cygwin-apps mailing list archives and look at the last few 
> days.  Hopefully there is a new perl coming soon that addresses your 
> problems; it should be available as a test version in the next few days. 
>   Once it is, PLEASE test it, Gavin.  None of "us" use text mounts...
> 
> --Chuck

No, unfortunately not, there are no changes to that issue.
I just tested the little example below, if used on a textmount,
there are \r's added to every line, so after the script
runs one time, a textfile is converted from \n to \n\r and everytime
it runs, one more \r is added.
It seems at this state, perl does the right job only on binmode mounts.

> Walker, Gavin (CMIS, ANU - Acton) wrote:
> 
> > Hi,
> >    I've been trying to write a perl script to edit a text file.  The cut
> > down version of it is a little further down.  It's pretty simple, read a
> > file in and dump it out.  My problem is that successive runs creates a
> > string of CR on each
> > line.  Every time I run it another CR is added.  To get rid of them I have to
> > use chomp, then chop and append my own \n.  Perl appears to be reading the
> > CR/LF characters separately and then out as CR/CR/LF.  This is supposed to
> > work on unix as well so I can't go chopping unnecessarily.  Running the same
> > program under DOS (probably using windows' perl) doesn't cause any problems. 
> > Perl version is 5.6.1 for cygwin.  On installation I told cygwin to use Dos
> > text format (cvs handles the dos/unix interchange).
> > 
> > Gavin Walker
> > Canberra, Australia
> > 
> > #!perl -w
> > use strict;
> > 
> > rename("file2","file1");
> > open(F1,"file1");
> > open(F2,">file2");
> > while(<F1>) {
> >     # have to use chomp; chop; print F2 $_ . "\n"; to get it to work
> >     print F2;
> > }
> > close(F1);
> > close(F2);


-- 
gerrit.haase@convey.de

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin 1.3.2-1 Problems with CR/LF in Perl
@ 2001-08-22 16:51 Walker, Gavin (CMIS, ANU - Acton)
  0 siblings, 0 replies; 7+ messages in thread
From: Walker, Gavin (CMIS, ANU - Acton) @ 2001-08-22 16:51 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

Thanks Scott, Troy, Charles & Gerrit,
    binmode() would work for the particular example but gets more
complicated
when I want to insert my own lines.  In binmode

print F1 "hi\n";

would not insert CR/LF like it's supposed to.  In my context the best
solution is to remove all trailing CR/LFs using

s/[\r\n]+$// 
or
chomp; $tmp=$/; $/="\r"; chomp; $/=$tmp;

or similar, and append my own "\n" when I need to.  There's only a small
risk that the CR/LFs are intentional.

Thanks again,

    Gavin Walker
    Canberra, Australia

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Cygwin 1.3.2-1 Problems with CR/LF in Perl
  2001-08-22  9:48 Troy Noble
@ 2001-08-22 10:46 ` Gerrit P. Haase
  0 siblings, 0 replies; 7+ messages in thread
From: Gerrit P. Haase @ 2001-08-22 10:46 UTC (permalink / raw)
  To: cygwin

> Troy Noble schrieb am 2001-08-22 10:48:

>So binmode(F1); or binmode(F2); didn't fix the behavior,
>even on textmode mount?

Yes, that's the workaround, but you will still have to fix
every unixscript which should handle files on textmounts.

The test script looks like that then:
=====================================
#!/usr/bin/perl -w
use strict;

rename("file2.txt","file1.txt");
open(F1,"file1.txt");
open(F2,">file2.txt");

binmode(F1);
binmode(F2);

while(<F1>) {
    # have to use chomp; chop; print F2 $_ . "\n"; to get it to work
    print F2;
}
close(F1);
close(F2);

>Just curious.  I know it's not a real fix, but is a
>potential work-around.  I suppose I could go try it
>for myself.

It works with my latest build and so should do the TRIAL release
from last year.

>The reason I mention it is that perldoc perlfunc says:

$ perldoc -f binmode

>"""
>binmode FILEHANDLE
>   Arranges for the file to be read or written in 
>``binary'' mode in operating systems that distinguish 
>between binary and text files. Files that are not in 
>binary mode have CR LF sequences translated to LF on 
>input and LF translated to CR LF on output. Binmode 
>has no effect under many sytems, but in MS-DOS and 
>similarly archaic systems, it may be imperative--otherwise 
>your MS-DOS-damaged C library may mangle your file. The 
>key distinction between systems that need binmode() 
>and those that don't is their text file formats. 
>Systems like Unix, MacOS, and Plan9 that delimit lines 
>with a single character, and that encode that character 
>in C as "\n", do not need binmode(). The rest may need 
>it. If FILEHANDLE is an expression, the value is taken 
>as the name of the filehandle. 
>
>If the system does care about it, using it when you 
>shouldn't is just as perilous as failing to use it 
>when you should. Fortunately for most of us, 
>you can't go wrong using binmode() on systems 
>that don't care about it, though.
>"""
>
>Troy
>
>-----Original Message-----
>From: Gerrit P. Haase [ mailto:cygwin@cygwin.com ]
>Sent: Wednesday, August 22, 2001 10:29 AM
>To: cygwin@cygwin.com
>Subject: Re: Cygwin 1.3.2-1 Problems with CR/LF in Perl
>
>
>>Charles Wilson schrieb am 2001-08-22 11:33:
>
>>Go to the cygwin-apps mailing list archives and look at the last few 
>>days.  Hopefully there is a new perl coming soon that addresses your 
>>problems; it should be available as a test version in the next few days. 
>>  Once it is, PLEASE test it, Gavin.  None of "us" use text mounts...
>> 
>>--Chuck
>
>No, unfortunately not, there are no changes to that issue.
>I just tested the little example below, if used on a textmount,
>there are \r's added to every line, so after the script
>runs one time, a textfile is converted from \n to \n\r and everytime
>it runs, one more \r is added.
>It seems at this state, perl does the right job only on binmode mounts.
>
>>Walker, Gavin (CMIS, ANU - Acton) wrote:
>> 
>>>Hi,
>>>I've been trying to write a perl script to edit a text file.  The cut
>>>down version of it is a little further down.  It's pretty simple, read a
>>>file in and dump it out.  My problem is that successive runs creates a
>>>string of CR on each line.  Every time I run it another CR is added.  To get
>>>rid of them I have to
>>>use chomp, then chop and append my own \n.  Perl appears to be reading the
>>>CR/LF characters separately and then out as CR/CR/LF.  This is supposed to
>>>work on unix as well so I can't go chopping unnecessarily.  Running the same
>>>program under DOS (probably using windows' perl) doesn't cause any problems. 
>>>Perl version is 5.6.1 for cygwin.  On installation I told cygwin to use Dos
>>>text format (cvs handles the dos/unix interchange).
>>>
>>>Gavin Walker
>>>Canberra, Australia
>>>
>>>#!perl -w
>>>use strict;
>>>
>>>rename("file2","file1");
>>>open(F1,"file1");
>>>open(F2,">file2");
>>>while(<F1>) {
>>>    # have to use chomp; chop; print F2 $_ . "\n"; to get it to work
>>>    print F2;
>>>}
>>>close(F1);
>>>close(F2);


-- 
gerrit.haase@convey.de

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Cygwin 1.3.2-1 Problems with CR/LF in Perl
@ 2001-08-22  9:48 Troy Noble
  2001-08-22 10:46 ` Gerrit P. Haase
  0 siblings, 1 reply; 7+ messages in thread
From: Troy Noble @ 2001-08-22  9:48 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

So binmode(F1); or binmode(F2); didn't fix the behavior,
even on textmode mount?

Just curious.  I know it's not a real fix, but is a
potential work-around.  I suppose I could go try it
for myself.

The reason I mention it is that perldoc perlfunc says:

"""
binmode FILEHANDLE
   Arranges for the file to be read or written in 
``binary'' mode in operating systems that distinguish 
between binary and text files. Files that are not in 
binary mode have CR LF sequences translated to LF on 
input and LF translated to CR LF on output. Binmode 
has no effect under many sytems, but in MS-DOS and 
similarly archaic systems, it may be imperative--otherwise 
your MS-DOS-damaged C library may mangle your file. The 
key distinction between systems that need binmode() 
and those that don't is their text file formats. 
Systems like Unix, MacOS, and Plan9 that delimit lines 
with a single character, and that encode that character 
in C as "\n", do not need binmode(). The rest may need 
it. If FILEHANDLE is an expression, the value is taken 
as the name of the filehandle. 

If the system does care about it, using it when you 
shouldn't is just as perilous as failing to use it 
when you should. Fortunately for most of us, 
you can't go wrong using binmode() on systems 
that don't care about it, though.
"""

Troy

-----Original Message-----
From: Gerrit P. Haase [ mailto:cygwin@cygwin.com ]
Sent: Wednesday, August 22, 2001 10:29 AM
To: cygwin@cygwin.com
Subject: Re: Cygwin 1.3.2-1 Problems with CR/LF in Perl


> Charles Wilson schrieb am 2001-08-22 11:33:

> Go to the cygwin-apps mailing list archives and look at the last few 
> days.  Hopefully there is a new perl coming soon that addresses your 
> problems; it should be available as a test version in the next few days. 
>   Once it is, PLEASE test it, Gavin.  None of "us" use text mounts...
> 
> --Chuck

No, unfortunately not, there are no changes to that issue.
I just tested the little example below, if used on a textmount,
there are \r's added to every line, so after the script
runs one time, a textfile is converted from \n to \n\r and everytime
it runs, one more \r is added.
It seems at this state, perl does the right job only on binmode mounts.

> Walker, Gavin (CMIS, ANU - Acton) wrote:
> 
> > Hi,
> >    I've been trying to write a perl script to edit a text file.  The cut
> > down version of it is a little further down.  It's pretty simple, read a
> > file in and dump it out.  My problem is that successive runs creates a
> > string of CR on each
> > line.  Every time I run it another CR is added.  To get rid of them I
have to
> > use chomp, then chop and append my own \n.  Perl appears to be reading
the
> > CR/LF characters separately and then out as CR/CR/LF.  This is supposed
to
> > work on unix as well so I can't go chopping unnecessarily.  Running the
same
> > program under DOS (probably using windows' perl) doesn't cause any
problems. 
> > Perl version is 5.6.1 for cygwin.  On installation I told cygwin to use
Dos
> > text format (cvs handles the dos/unix interchange).
> > 
> > Gavin Walker
> > Canberra, Australia
> > 
> > #!perl -w
> > use strict;
> > 
> > rename("file2","file1");
> > open(F1,"file1");
> > open(F2,">file2");
> > while(<F1>) {
> >     # have to use chomp; chop; print F2 $_ . "\n"; to get it to work
> >     print F2;
> > }
> > close(F1);
> > close(F2);


-- 
gerrit.haase@convey.de

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

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Cygwin 1.3.2-1 Problems with CR/LF in Perl
@ 2001-08-22  7:37 Troy Noble
  0 siblings, 0 replies; 7+ messages in thread
From: Troy Noble @ 2001-08-22  7:37 UTC (permalink / raw)
  To: 'Walker, Gavin (CMIS, ANU - Acton)', 'cygwin@cygwin.com'

Try

bash$ mount

Does it report your mount point as textmode or binmode?
Probably textmode.

Consider:

http://www.cygwin.com/ml/cygwin/2001-04/msg00194.html
http://www.cygwin.com/ml/cygwin/2001-03/msg00494.html

With textmode IIRC the default behavior is to
convert the line endings when outputting to text files.
Perhaps you could change your mount point to binmode
instead and try that, or open your input or output file
in binary mode instead of text mode.  I suspect either
would fix it.  I don't have cygwin Perl installed at
the moment, so can't try it out here myself.  Just
remembering the solutions mentioned by others in
prior postings on this topic...

Troy

-----Original Message-----
From: Walker, Gavin (CMIS, ANU - Acton)
[ mailto:Gavin.Walker@cmis.csiro.au ]
Sent: Wednesday, August 22, 2001 6:39 AM
To: 'cygwin@cygwin.com'
Subject: Cygwin 1.3.2-1 Problems with CR/LF in Perl


Hi,
   I've been trying to write a perl script to edit a text file.  The cut
down version of it is a little further down.  It's pretty simple, read a
file in and dump it out.  My problem is that successive runs creates a
string of CR on each
line.  Every time I run it another CR is added.  To get rid of them I have
to use chomp, then chop and append my own \n.  Perl appears to be reading
the CR/LF characters separately and then out as CR/CR/LF.  This is supposed
to work on unix as well so I can't go chopping unnecessarily.  Running the
same program under DOS (probably using windows' perl) doesn't cause any
problems.  Perl version is 5.6.1 for cygwin.  On installation I told cygwin
to use Dos text format (cvs handles the dos/unix interchange).

Gavin Walker
Canberra, Australia

#!perl -w
use strict;

rename("file2","file1");
open(F1,"file1");
open(F2,">file2");
while(<F1>) {
    # have to use chomp; chop; print F2 $_ . "\n"; to get it to work
    print F2;
}
close(F1);
close(F2);

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

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-08-22 16:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-22  5:39 Cygwin 1.3.2-1 Problems with CR/LF in Perl Walker, Gavin (CMIS, ANU - Acton)
2001-08-22  8:33 ` Charles Wilson
2001-08-22  9:34   ` Gerrit P. Haase
2001-08-22  7:37 Troy Noble
2001-08-22  9:48 Troy Noble
2001-08-22 10:46 ` Gerrit P. Haase
2001-08-22 16:51 Walker, Gavin (CMIS, ANU - Acton)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).