From: Aredridel Date: 2004-07-03T01:33:40+09:00 Subject: Re: Help with one-liner On Sat, 2004-07-03 at 01:13 +0900, Philip Mateescu wrote: > Hello, > > I'm having problems with an one-liner (ruby 1.6.8 (2003-02-25) > [i386-cygwin]). > > 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 "---" > > --- > ---ging nha-a30p-009.nha.corp [127.0.0.1] with 32 bytes of data: > --- > ---ly from 127.0.0.1: bytes=32 time<1ms TTL=128 > ---ly from 127.0.0.1: bytes=32 time<1ms TTL=128 > ---ly from 127.0.0.1: bytes=32 time<1ms TTL=128 > ---ly from 127.0.0.1: bytes=32 time<1ms TTL=128 > --- > ---g statistics for 127.0.0.1: > --- Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), > ---roximate round trip times in milli-seconds: > --- Minimum = 0ms, Maximum = 0ms, Average = 0ms > > What am I doing wrong? And why? :) You're one windows, so the line ending coming out of ping is \r\n, not \n -- chomp! isn't eating that, and leaving the carriage-return, but not the linefeed. So it prints the whole line, returns to the start, prints three dashes, then newlines and starts again. Take two characters off the end instead of one and it should work. Ari