DATA and $

Is it correct that the first line read from DATA has not $. == 1 ?
(This differs from Perl)

#!/usr/local/bin/ruby
DATA.each { |d| puts "lineno: #{$.} has: #{d}" }
__END__
1
2
3

=>
lineno: 4 has: 1
lineno: 5 has: 2
lineno: 6 has: 3

···

--
Wybo

You could hardly reconcile $. == 1 with this:

batsman@tux-chan:~/mess/current$ cat data.rb
DATA.rewind
DATA.each{|l| puts "lineno: #{$.} -> #{l}" }
__END__
foo
batsman@tux-chan:~/mess/current$ ruby data.rb
lineno: 1 -> DATA.rewind
lineno: 2 -> DATA.each{|l| puts "lineno: #{$.} -> #{l}" }
lineno: 3 -> __END__
lineno: 4 -> foo

···

On Mon, Jun 19, 2006 at 09:28:40PM +0900, Wybo Dekker wrote:

Is it correct that the first line read from DATA has not $. == 1 ?
(This differs from Perl)

#!/usr/local/bin/ruby
DATA.each { |d| puts "lineno: #{$.} has: #{d}" }
__END__
1
2
3

=>
lineno: 4 has: 1
lineno: 5 has: 2
lineno: 6 has: 3

--
Mauricio Fernandez - http://eigenclass.org - singular Ruby