Whats wrong with this script?

T

Tommy Nordgren

#!/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
 
S

Simon Krahnke

* Sebastian Hungerecker said:
Typo: there is no variable $headersumfilefile, only $headersumfile.

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

mfg, simon .... l
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top