Whats wrong with this script?


#1

#!/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 methodputs’ called for
nil:NilClass (NoMethodError)
from ./extractdata.rb:20:in each' from ./extractdata.rb:20:inscanfiles’
from ./extractdata.rb:19:in open' from ./extractdata.rb:19:inscanfiles’
from ./extractdata.rb:9:in each' from ./extractdata.rb:9:inscanfiles’
from ./extractdata.rb:25:in scanfiles' from ./extractdata.rb:9:ineach’
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


#2

Tommy N. wrote:

$headersumfilefile.puts(l);

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

HTH,
Sebastian


#3

Tommy N. 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