From: Robert Klemme Date: 2009-08-19T16:14:26+09:00 Subject: Re: fromdos dos2unix in ruby 2009/8/18 Xavier Noria : > On Tue, Aug 18, 2009 at 10:15 PM, Robert > Klemme wrote: > >> WIN_LE = "\r\n".freeze >> >> File.open ARGV[0] do |in| >>  File.open ARGV[1], "wb" do |out| >>    in.each do |line| >>      line.chomp! >>      out.print line, WIN_LE > > Hey but this is dos2unix :-). Ooops, make that then LE = "\n".freeze and of course out.print line, LE > You can't read in text-mode just like that in a portable way, because > chomp! only chomps "\n". No. $ allruby -e 'p "a\r\n".chomp' CYGWIN_NT-5.1 padrklemme1 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin ======================================== ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] "a" ======================================== ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-cygwin] "a" > If you can assume the program is gonna run only on Windows then the > solution is trivial: read in text-mode, and write in binary mode. No > chomping or gsubs needed, just read and write. > > If the program has to be portable then you need to deal with the > spurious \015 that may come up. String#chomp does that nicely. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/