> > MatchData is not data by itself, it points to $1, $2,... So
> > this doesn't work:
> 
> See http://dev.rubycentral.com/articles/re_obj.html

Thanks for nice article.

Missed however the point here a little, while clearing the relationship
between $dollar_variables and the rest of the Ruby.

The point here was that Aleksi is still digging up issues because he's
stupid enough to keep on messing with 1.4 series :).

BTW. You might want add a point to the article. I though exactly what you
did about $1 -variables with 

  re = /(\d+):(\d+)/
  md1 = re.match("Time: 12:34am")
  md2 = re.match("Time: 10:30pm")
  [ $1, $2 ]   # last successful match      # -> ["10", "30"]
  $~ = md1
  [ $1, $2 ]   # previous successful match  # -> ["12", "34"]

Then I became aware of concurrency in Ruby and made a test. I couldn't make
$1 point anything but the last successful match. *On that thread*! 

That means interleaved execution like this.

         Thread 1                        Thread 2

   s =~ /matches foo 1/
   <thread 1 loses execution>         <thread 2 gets execution turn>

                                      s =~ /matches foo 2/  
   <thread 1 gets execution turn>     <thread 2 loses execution>


   p $1  # => "matches foo 1"
   <thread 1 loses execution>         <thread 2 gets execution turn>

                                       p $1   #=> "matches foo 2"

The program making it clear is here (or does it make anything clear :):

  def threadFactory(str)
    Thread.start do 
      s = "matches #{str}"
      /(#{s})/.match(s)
      p $1
      Thread.stop
      p $1
    end
  end

  threads = []
  4.times do |i|
    threads << threadFactory("foo #{i}")
  end

  threads.each do |t| t.wakeup end
 
  threads.each do |t| t.join end

With the output:

  "matches foo 0"
  "matches foo 1"
  "matches foo 2"
  "matches foo 3"
  "matches foo 3"
  "matches foo 2"
  "matches foo 1"
  "matches foo 0"

The statement of "last successful match" implicates that this is not the
behaviour and all 'p $1' statements on my example should print "matches
bar".

But this is a nitty gritty detail of concurrency, right? Nope. The same
applies to routines too:

  def foo(str)
    /(foo)/.match(str)
    bar(str)
    p $1      # the *latest* successful match has happened at bar
  end

  def bar(str)
    /(bar)/.match(str)
    p $1
  end

  foo("foo bar")

Outputting:

  "bar"
  "foo"

So $globals are not so globals after all. Njaah, I'm just mixing things :).

	- Aleksi