# Bug in $.?

**URL:** <https://rubytalk.org/t/bug-in/28323>\
**Category:** ruby-talk\
**Created:** [20 June 2006 10:05 UTC](https://rubytalk.org/t/bug-in/28323 "2006-06-20T10:05:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wybo\_Dekker](https://avatars.discourse-cdn.com/v4/letter/w/ee59a6/32.png) [@Wybo\_Dekker](https://rubytalk.org/u/Wybo_Dekker)\
**Post date:** [20 June 2006 10:05 UTC](https://rubytalk.org/t/bug-in/28323/1 "2006-06-20T10:05:57Z")

</div>

> cat t

def out; print "#$. "; end # print $. plus a space  
out  
$. = 0  
out  
DATA.each { out }  
puts  
\_\_END\_\_  
1  
2  
3  
4

> 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?

> **···**
>
> --  
> Wybo

---

<div class="post-metadata">

**Author:** ![Mike\_Fletcher](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@Mike\_Fletcher](https://rubytalk.org/u/Mike_Fletcher)\
**Post date:** [20 June 2006 12:37 UTC](https://rubytalk.org/t/bug-in/28323/2 "2006-06-20T12:37:26Z")

</div>

Wybo Dekker wrote:

> \>cat t  
> def out; print "#$. "; end # print $. plus a space  
> out  
> $. = 0  
> out  
> DATA.each { out }  
> puts  
> \_\_END\_\_  
> 1  
> 2  
> 3  
> 4  
> \>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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
