You're probably right about the line ending, here's a variation:
$ ping localhost | ruby -e '$<.each_line { |line| chomp1 = line.chomp();
chomp_rn = line.chomp("\r\n"); chomp_r = line.chomp("\r"); chomp_n =
line.chomp("\n"); puts chomp1 + "-- 1--"; puts chomp_rn + "--rn--"; puts
chomp_r + "-- r--"; puts chomp_n + "-- n--"; }'
And the result:
-- 1--from 127.0.0.1: bytes=32 time<1ms TTL=128
--rn--from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
-- r--
-- n--from 127.0.0.1: bytes=32 time<1ms TTL=128
Baffling....
Aredridel wrote:
> 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
>
>
>
Best regards.
philip
----
All I ask is a chance to prove that money can't make me happy.
---