# Bug in $.?

**URL:** <https://www.ruby-forum.com/t/bug-in/95937>\
**Category:** Ruby\
**Created:** [June 20, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/bug-in/95937 "2006-06-20T12:08:32Z")\
**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 20, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/bug-in/95937/1 "2006-06-20T12:08:32Z")

</div>

wybo\>cat t  
def out; print "#$. "; end # print $. plus a space  
out  
$. = 0  
out  
DATA.each { out }  
puts  
**END**  
1  
2  
3  
4  
wybo\>ruby t  
7 0 8 9 10 11

This should, probably even without the $.=0 statement, print:  
7 0 1 2 3 4

Am I wrong?

---

<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 20, 2006, 2:37pm UTC](https://www.ruby-forum.com/t/bug-in/95937/2 "2006-06-20T14:37:07Z")

</div>

Wybo D. wrote:

> wybo\>cat t  
> def out; print "#$. "; end # print $. plus a space  
> out  
> $. = 0  
> out  
> DATA.each { out }  
> puts  
> **END**  
> 1  
> 2  
> 3  
> 4  
> wybo\>ruby t  
> 7 0 8 9 10 11
> 
> This should, probably even without the $.=0 statement, print:  
> 7 0 1 2 3 4
> 
> Am I wrong?

What looks like is happening (with no opinion as to it’s correctness):

- DATA.lineno is 7 (6 lines of code + the **END** line), so the initial  
value’s reasonable

- when you assign to $. it’s affecting $\<.lineno (which makes sense)

- however when you do “$. = 0”, $\< is the handle ARGF, not DATA

- after the code was read, $\< got changed to the ARGF handle but $.  
wasn’t reset

- you then start reading from DATA, so $. gets associated with it again  
and $. is back to 7
