Strange behavior of $

Apparently $. is not always set correct (see second ruby 1liner). Is this
a bug?

12:12:42 [temp]: cat -n n
1
2
3 BAR="hello"
4
12:12:47 [temp]: ruby -ne ‘puts $.’ n
1
2
3
4
12:12:56 [temp]: ruby -e ‘while(line = gets); puts “#{$.}:#{line.chomp}”;
end’ n
1:
1:
2:BAR="hello"
3:
12:13:10 [temp]: ruby --version
ruby 1.8.0 (2003-08-04) [i386-cygwin]
12:13:35 [temp]:

The same happens when put into a script:

12:16:02 [temp]: ./x.rb n
1:
1:
2:BAR="hello"
3:
12:16:03 [temp]: cat x.rb
#!/usr/bin/ruby

while ( line = gets )
puts "#{$.}:#{line.chomp}"
end

12:16:12 [temp]:

Any ideas?

Regards

robert

Hi,

···

At Wed, 17 Sep 2003 19:34:38 +0900, Robert Klemme wrote:

12:12:56 [temp]: ruby -e ‘while(line = gets); puts “#{$.}:#{line.chomp}”;
end’ n
1:
1:
2:BAR=“hello”
3:
12:13:10 [temp]: ruby --version
ruby 1.8.0 (2003-08-04) [i386-cygwin]

It feels fixed already.


Nobu Nakada