# Parsing a spice netlist, need to be faster

**URL:** <https://www.ruby-forum.com/t/parsing-a-spice-netlist-need-to-be-faster/128556>\
**Category:** Ruby\
**Created:** [February 8, 2008, 8:12pm UTC](https://www.ruby-forum.com/t/parsing-a-spice-netlist-need-to-be-faster/128556 "2008-02-08T20:12:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reactorman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@reactorman](https://www.ruby-forum.com/u/reactorman)\
**Post date:** [February 8, 2008, 8:12pm UTC](https://www.ruby-forum.com/t/parsing-a-spice-netlist-need-to-be-faster/128556/1 "2008-02-08T20:12:14Z")

</div>

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
