From: ts Date: 2001-03-30T20:32:01+09:00 Subject: [ruby-talk:13354] Re: Why is $_ local to the current scope? >>>>> "J" == Jeremy Henty writes: J> In the chapter "The Ruby Language" of "Programming Ruby", $_ is the J> only variable under the heading "Input/Output Variables" that has J> local scope, so it seems a bit anomalous. $_ and $~ make reference to local variables. They are also thread local variables. If $_ was a global variable, it will be very difficult to use it. Just imagine 2 methods which work with $_. The first read a line, then call the second method (which modify $_). When the second method return you have lost the content of $_. This can give bug very difficult to find. You have a similar problem, in a P language, when you forget 'local $_' in a sub and call another sub which modify $_. J> Also, I'm surprised that 'ARGF.each do ...' sets $. but not $_. Again J> I don't see the reason for this. Enlightenment will be welcomed! Well ruby-man say $_ : The last input line of string by gets or readline. ^^^^ ^^^^^^^^ $_ is set when you use the object as a file (sort of). When you use it as an iterator you can always write ARGF.each do |$_| # end Guy Decoux