in reply to using an external file as a hash
A very simple approach is to write key/value pairs out seperated by a delimiter, such as a colon, comma, or pipe character. Put a line break after each key/val pair. Reading it back in, is as easy as reading one line at a time and splitting it on the delimiter.
Another approach is to use the Storable module, which can store data-structures for you quickly and easily. And the same can be read back in just as easily.
Another approach is a variation on what Data::Dumper can be made to do; write your data-set out as executable Perl, and then upon retrieval, eval it. This opens you up to some potential security risks and other cans of worms, but it's a possibility you see in use once in awhile.
Another obvious approach is to just tie your hash directly to a file. Access and use couldn't be easier. Though you do have to be concerned with the fact that this solution (as well as the other ones mentioned so far in this followup node) doesn't scale well to larger projects.
If you need a more scalable solution, think databases. The DBI.pm module can team up with DBD::SQLite or DBD::CSV to create either a self-contained database (or CSV database) without all the hastles of installing and maintaining something like MySQL.
Lots of options, lots to think about. I think that in some cases coming up with the right data storage strategy is the most important design consideration.
I hope the thoughts and links help...
Dave
|
|---|