From: Geoff Youngs Date: 2004-07-03T01:31:15+09:00 Subject: Re: Help with one-liner Philip Mateescu wrote: > My one liner sample: > > $ ping localhost | ruby -e '$<.readlines.each { |line| line.chomp!(); > puts(line + "---\n"); }' > > I would expect it to put --- at the end of each line. Instead it > replaces the first 3 chars of each line with "---" > [snip] > What am I doing wrong? And why? :) Probably line endings - windows line endings are "\r\n" - and chomp! seems to only be removing the "\n", so the carriage return is returning the cursor to the beginning of the line before trying to display the "---\n" string. Try using line.rstrip! to remove all trailing whitespace, or line.chomp!("\r\n"). Unless you want to process the entire output of the ping command at once, using IO#each_line might be better than IO#readlines. Also, the "\n" at the end of the string isn't needed - IO#puts is capable of adding one automatically. HTH, Geoff.