# DATA and $

**URL:** <https://www.ruby-forum.com/t/data-and/95912>\
**Category:** Ruby\
**Created:** [June 19, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/data-and/95912 "2006-06-19T14:30:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [June 19, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/data-and/95912/1 "2006-06-19T14:30:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [June 19, 2006, 2:49pm UTC](https://www.ruby-forum.com/t/data-and/95912/2 "2006-06-19T14:49:59Z")

</div>

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

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

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
