Hi,

2009/7/24 Mike Kasick <mkasick-rt / club.cc.cmu.edu>:
> Hi folks,
>
> In Ruby 1.8, I know that:
>
> $ ruby -e 'while !ARGF.eof?; puts ARGF.readline; end' /tmp/foo /tmp/bar
>
> prints every line in /tmp/foo, but not /tmp/bar. However, in Ruby 1.9:
>
> $ ruby1.9 -e 'p ARGF.eof?' /tmp/foo
> true
>
> Which means that lines from neither /tmp/foo nor /tmp/bar would be printed
> in the first example. Is this an expected change in behavior? Seems to be
> consistent for both 1.9.1p0 and the 1.9.2 svn trunk I just compiled.
>
> If it is, it's not that big of a deal, except I'm not sure how to "switch
> ARGF" to the next file without calling ARGF.gets or ARGF.readline.
>
> For example, is there a method to complete the following code, so as to
> print lines from all files listed in ARGV?
>
> while !ARGV.empty?
>  # ARGF.some_method_to_advance_to_next_file
>
>  while !ARGF.eof?
>   puts ARGF.readline
>  end
> end
>
You can use ARGF.each for both 1.8.x and 1.9.x.

Try
$ ruby -e 'ARGF.each{|l|puts l}' /tmp/foo /tmp/bar

Regards,

Park Heesob