From: Adam Chamberlain Date: 2008-02-09T04:12:07+09:00 Subject: Parsing a spice netlist, need to be faster Hey guys! I am writing some code that has gotten far too slow. I am reading files that have the following types of statements: This is all test written in a file +bob = 2 +roger = 3 +barn = 'bob' +frank = '3 + roger' +nancy = 'roger*6 ' gary =4 jason= 'bob+roger' It cannot be assumed that bob will be declared before barn, though I would like to know if it isn't in certain modes. I want to be able to read all these parameters in (there will be roughly 20,000 of them) and be able to dump them into an object. That way I can do something like a["nancy"] and get 18. The code is currently too slow. I need to read parse strings really fast and be able to evaluate these statements. For example, if I read in '3 + roger' and do an eval(a), there will be a nomethod error because roger is not defined. I cannot have roger as a variable because I can't keep it in scope. Instead I have to pick the line apart and get 'roger' out of it, then I search through the hash table to find where roger is. This implementation works but is incredibly slow. I need someone to point me to some good practices in Ruby for parsing text and trying to evaluate what's found. I also recognize the danger of the eval command. I have taken steps to limit what can and can't reach the eval statement. For example, it is impossible for backticks to reach the eval command, removing one method of making a system call within the evla statement. Adam -- Posted via http://www.ruby-forum.com/.