Whats wrong with this script?

#!/usr/bin/ruby

$headersumfile = File.open("Header-summary.txt","w");

$finalizerfile = File.open("Finalizers.m","w");

def scanfiles(dirhand, dirname)

  dirhand.each { | fn |
    if (fn == '.' || fn == '..')
    
    elsif (fn =~ /\.m$/)
      File.open("#{dirname}/#{fn}","r") { | f |
        f.each { | l |
          $finalizerfile.puts(l);
        }
      }
    elsif (fn =~ /\.h$/)
      File.open("#{dirname}/#{fn}","r") { | f |
        f.each { | l |
          $headersumfilefile.puts(l);
        }
      }
    elsif (File.directory?("#{dirname}/#{fn}"))
      scanfiles(Dir.open("#{dirname}/#{fn}"),"#{dirname}/#{fn}")
    end
  }
  dirhand.close;
end

scanfiles(Dir.open("Source"),"Source");

$finalizerfile.close;
$headersumfile.close;

Message from terminal:
emac$ ./extractdata.rb
./extractdata.rb:21:in `scanfiles': private method `puts' called for nil:NilClass (NoMethodError)
  from ./extractdata.rb:20:in `each'
  from ./extractdata.rb:20:in `scanfiles'
  from ./extractdata.rb:19:in `open'
  from ./extractdata.rb:19:in `scanfiles'
  from ./extractdata.rb:9:in `each'
  from ./extractdata.rb:9:in `scanfiles'
  from ./extractdata.rb:25:in `scanfiles'
  from ./extractdata.rb:9:in `each'
  from ./extractdata.rb:9:in `scanfiles'
  from ./extractdata.rb:31
Work Directory: ~/Desktop/Drawkit/DrawKit/Trunk :

The script are supposed to copy objective source and header files to a pair of files.
The directory to be scanned exists in my current work directory.
Can someone please help

···

----------------------------------
Skinheads are so tired of immigration, that they are going to move to a country that don't accept immigrants!
Tommy Nordgren
tommy.nordgren@comhem.se

Tommy Nordgren wrote:

$headersumfilefile.puts(l);

Typo: there is no variable $headersumfilefile, only $headersumfile.

HTH,
Sebastian

···

--
NP: J.B.O. - La Ichobein
Jabber: sepp2k@jabber.org
ICQ: 205544826

* Sebastian Hungerecker <sepp2k@googlemail.com> (00:40) schrieb:

Tommy Nordgren wrote:

$headersumfilefile.puts(l);

Typo: there is no variable $headersumfilefile, only $headersumfile.

That seems to be another reason not to use global variables.

mfg, simon .... l