From: Robert Klemme Date: 2011-03-02T19:59:57+09:00 Subject: Re: why is $1 in a grep() equal to nil? On Tue, Mar 1, 2011 at 8:53 PM, 7stud -- wrote: > Robert Klemme wrote in post #984624: >> On Fri, Feb 25, 2011 at 9:53 PM, 7stud -- >> wrote: >>>> worry >>>>  meth_a >>> Uh oh. Someone is going to have to explain that to me. $1 does not act >>> like a regular global variable: >> >> $1, $2 etc. look like global variables but they are in fact local to >> the scope where they are set. > > Thanks for the response Robert. > > As far as I can tell, there is a difference between $1 and a local > variable. Yes, of course. > The output shows that in all the procs, the value of $1 is the value > produced by the last regex match.  Yet a new name variable is created > every time through the each loop, and each proc closes over a different > name variable.  So there is a difference between a local variable like > name and $1. This is true but I never claimed differently. I wrote "they are local to the scope..." and not "they are local variables". :-) Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/