|Syntactic Confectionery Delight|
Re^3: Seeing Perl in a new light: Epilogby TGI (Vicar)
|on Sep 25, 2010 at 18:56 UTC||Need Help??|
Speed is a valid concern. But before you get to worried about it, try it the change and see if it is actually a problem. It may not be as slow as you think. And as my mom always said "Don't borrow trouble." But if speed is a problem, there are ways to move forward.
Two common solutions exist for the problem of having to open and parse too many files. 1. Use a database 2. Pre-process the files and cache the results. I'm just guessing, but I believe that you have zero interest in digging into the world of databases right now. That leaves preprocessing.
Your current method is a form of pre-processing where you are the processor. You manually convert the list of monsters in your CSV file into a group of files. Then the menu script looks into the directory and makes the menu based on the file names. When you add or remove a monster, you manually add or remove a .pl file.
Instead of this manual process, have a script that does whatever needs to happen to generate a data structure that represents your menu. Probably series of nested arrays. Then save that data structure to a file, using Storable is probably the simplest and best way since it is core and fast.
Now when you want to generate the HTML for your menu, instead of redoing the work of processing all the files, simply load the data from your file and generate html.
This approach should lead to a couple of benefits:
I am assuming that you can write code to traverse the $menu_data structure. If not, let me know and I can demonstrate the required concepts.
My comments here are based on my understanding of the following statement. If they don't make sense, then I probably misunderstood you.
Currently, the Monster directory has a .pl file for each monster. Those are loaded into the menu script.
I understand this to mean you scan the file names and use those to populate the menu.