On Fri, Jun 14, 2013 at 1:14 AM, Eric Christopherson <
echristopherson / gmail.com> wrote:

> On Thu, Jun 13, 2013 at 4:49 PM, Greg Ferguson <lists / ruby-forum.com>wrote:
>
>> How come Ruby outputs the incoming piped text when there is no code to
>> evaluate:
>>
>>     echo foo | ruby -pe ''
>>
>> outputs: "foo"
>>
>> Without "-p" there's no output, which I'd expect. Without '' there's an
>> error, which I'd expect when using the "-e" flag.
>>
>> Is there a silent return value of the incoming text that "-p" is then
>> printing?
>>
>
> Not a return value.
>
> From `ruby --help`:
>   -n              assume 'while gets(); ... end' loop around your script
>   -p              assume loop like -n but print line also like sed
>
> So it creates a loop around the (empty) expression; the loop keeps getting
> the next line from stdin until EOF; and it prints the line. (Actually I
> believe the line printed is the special variable $_, which gets writes to
> implicitly. In an actual useful one-liner you would probably filter out
> certain lines and/or run sub or gsub -- when invoked as Kernel methods,
> these  also implicitly write to $_.)
>

Btw, that's what other tools do as well:

$ seq 1 5 | sed -e ''
1
2
3
4
5

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/