in reply to Can't get rid of \r

The above works find on Windows (once you change "$csfile" to "$inp" and change "join "\n"" to "join """).

Are you using a Cygwin build? I'm not sure how that would work.

Replies are listed 'Best First'.
Re^2: Can't get rid of \r
by rovf (Priest) on Sep 12, 2008 at 08:46 UTC
    once you change "$csfile" to "$inp"

    Thanks for pointing this out. In my attempt to provide more meaningful variable names for the code posted, I overlooked that one.

    -- 
    Ronald Fischer <ynnor@mm.st>
Re^2: Can't get rid of \r - SOLVED (Kind of)
by rovf (Priest) on Sep 12, 2008 at 09:28 UTC
    The above works find on Windows - Are you using a Cygwin build?

    I'm running the program under plain Windows at the moment...

    But programming is a black art, really. When I came back to work today, with some ideas how to test it, I found that the program runs fine, without any modifications - no extra \r anymore on output! Of course I still had the bug of extra \n, because of the way I read in my data, but this was trivial to correct. In short: I have no idea why it didn't work yesterday, but works well today. Creepy.

    For completeness, here is the full code (unmodified) which I'm using to test. In particular, I did not yet try the (neat) idea of using raw mode. It turned out to be unnecessary in this case:

    use strict; use warnings; use IO::File; # copy \n delimited file from Windows to # Samba share on Unix. Output is also # supposed to be delimited by \n my $par='c:/tmp/dev.cs'; my $file=new IO::File $par,'r' or die "$!"; my $data=join '',<$file>; # !!!! undef $file; my $_path_local='u:/transfer/devc.cs'; my $handle=IO::File->new($_path_local,'w') or die "$!"; $handle->binmode; print $handle $data; $handle->close;
    My best explanation for the fact that it suddenly turned out to work overnight is that I mistakingly grabbed an old version of my application from our source control system (a version which did not have the binmode set), and used *that* one instead of the version I had in my editor. Not likely, but the best explanation aside from a miracle having happened.

    Thank you to everyone for contributing ideas.

    -- 
    Ronald Fischer <ynnor@mm.st>