tomazos has asked for the wisdom of the Perl Monks concerning the following question:
My requirements go beyond the basic hash-storing file provided by the DBM routines, but are not so advanced as to require mSQL/MySQL or similar.
Basically I want a file that stores a "two dimensional hash" with the main key being the user's email address, and secondary keys being things like name, serial number, status etc. I want to be able to add/delete secondary keys easily later.
I was thinking to just build this on top of DBM by serializing the secondary hash for each record, but surely someone else must have been here before and has code I can reuse?
Anyone know of anything that may address these needs?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Basic Database?
by jeroenes (Priest) on Jun 11, 2001 at 17:56 UTC | |
..to populate your DB; You can fetch items in a similar fashion with split; Hope this helps, Jeroen | [reply] [d/l] |
Re: Basic Database?
by andreychek (Parson) on Jun 11, 2001 at 18:10 UTC | |
This is the README file for MLDBM, the Perl module that can be used to store multidimensional hash structures in tied hashes (including DBM files). I can't actually check the documentation because <whine> CPAN is down </whine>, but I believe it uses Data::Dumper to store Perl data types in the DB. Good luck! -Eric | [reply] |
by rob_au (Abbot) on Jun 11, 2001 at 18:42 UTC | |
Another way which I have stored complex data structures before has been through the Storable module - This wonderful module even allowed me to store user preference hashes for a web site in a cookie! Ooohhh, Rob no beer function well without! | [reply] [d/l] |
Re: Basic Database?
by Spudnuts (Pilgrim) on Jun 11, 2001 at 18:33 UTC | |
| [reply] |
by pmas (Hermit) on Jun 11, 2001 at 19:46 UTC | |
You wil learn something new and important. Market value of your skills will increase. SQL database is standard way to store data in the industry. SQL is portable enough so next time you are ready to store data in ORACLE. From other point of view, learning ::Storable or other proposed solutions is great if you are already familiar with SQL databases. Obviously I assume you have time to try and learn new tools. Given enough time, and if you are not familiar enough with databases, I will recommennd to go SQL database route. It will be pain to digest database concepts, learn new (SQL) language, but it will benefit you immensely. Database itself looks simple and straightfooward (just one table), excellent for your first project. And maybe you can thought out some related table and JOIN them. This allows you to join SQL DB club... : ) pmas To make errors is human. But to make million errors per second, you need a computer. | [reply] |
Re: Basic Database?
by gildir (Pilgrim) on Jun 11, 2001 at 19:14 UTC | |
*DBM
database/directory | [reply] |
by eduardo (Curate) on Jun 11, 2001 at 19:24 UTC | |
And if you want to do a substring search, there is no easy method except for linear search. And that could be terribly slow even for small database.In DB_File under the section Matching Partial Keys we see: Matching Partial Keys The BTREE interface has a feature which allows partial keys to be matched. This functionality is only available when the seq method is used along with the R_CURSOR flag. Here is the relevant quote from the dbopen man page where it defines the use of the R_CURSOR flag with seq: Note, for the DB_BTREE access method, the returned key is not necessarily an exact match for the specified key. The returned key is the smallest key greater than or equal to the specified key, permitting partial key matches and range searches.In the example script below, the match sub uses this feature to find and print the first matching key/value pair given a partial key. Here is the output: IN ORDER Smith -> John Wall -> Larry Walls -> Brick mouse -> mickey PARTIAL MATCH Wa -> Wall -> Larry A -> Smith -> John a -> mouse -> mickeySo, although I don't know how it is that DBM implements that internally, it does seem like it would give you a little bit more functionality (or at least a more elegant interface) than just a linear search. Comments? | [reply] [d/l] [select] |
by gildir (Pilgrim) on Jun 11, 2001 at 19:46 UTC | |
That will allows you to search for foo*, but not for *foo nor *foo*. Substring search is *foo*-like, but you are right about the 'added functionality'. In some cases even foo* search can be sufficient. | [reply] |
Re: Basic Database?
by bikeNomad (Priest) on Jun 11, 2001 at 19:31 UTC | |
Joins (though the underlying Sleepycat BerkeleyDB supports them) are not yet supported (though the manpage says that support is in progress). However, you could use the fine-grained locking and multiple tables to do joins manually. | [reply] |
Re: Basic Database?
by extremely (Priest) on Jun 12, 2001 at 06:20 UTC | |
-- | [reply] |
by mattr (Curate) on Jun 12, 2001 at 13:51 UTC | |
I actually was going to write a comment saying, "Don't use DBD::CSV. You will go insane. Okay?". It actually is quite nice and I was delighted with DBD::CSV at first. But I found wierd bugs crawling in and though I still have a project using it, find it a little fragile and unscalable. True, I implemented it soon after it came out so maybe it is much better now. But you also want to be careful with things that could break CSV, especially (sounds dumb but..) vertical tabs from Excel. In fact, Excel is evil. View something in Excel if you like but if you must edit in Windows, use Access! Excel CSV generation is broken. I suppose Windows vs. Unix and also doing it all in Japanese didn't help so maybe it was a bit of a stress test. I also hacked SQL/HTML v1.0 by Jonathan A. Zdziarski to work with DBD::CSV for a quick internal admin interface to the db, which was pushing things a bit. Also if you think you have a unique key you will have to strongly enforce its uniqueness every step of the way. That said, it works for very basic things. Best use of it I would think is if you periodically received a CSV file and wanted to deal with it in SQL. I really enjoyed how easy it was to write the search algorithms with SQL. But keep backups and go look at and possibly edit the raw file periodically please. That said, DBD::CSV does work and you can see it working in the event calendar of the Royal Netherlands Embassy in Japan. (The free text engine is different algorithm, not SQL). There is another thing, you could have some flat file or other which you slurp into memory and then manipulate with DBD::RAM. I keep trying to find some reason to try working with it.. Hey I just installed it from cpan, it's back up again! I wonder which is faster, DBD::CSV or slurp + DBD::RAM ?..
Updated:Yow! Turns out DBD::RAM works with not only local CSV files, but also files accessible via http and ftp, and it even works on arrays and hashes? Woohoo! I think I like the idea of using DBD::RAM better than DBD::CSV because I can migrate data to a different format if I decide it needs to be binary, and I don't try to fool myself thinking my flat file is an SQL database engine. Seems you can separate the SQL query interface and the data I/O to some degree. Maybe a separate perl process to maintain that in memory plus IPC? Interested in anyone with experience with RAM. Funny, it says in the man page that you can have it write to disk for every modification of the db. I wonder if that would satisfy some people who are worried about Mysql putatively not saving data quickly. | [reply] [d/l] |
Re: Basic Database?
by Anonymous Monk on Jun 11, 2001 at 23:45 UTC | |
1. USE STORABLE not Data::Dumper!!! Storable is about an order of magnitude faster for my tasks. The serialization package that MLDBM uses is customizable. See the docs. 2. Consider your memory needs. I've found that not only does the serialization package incur a signifigant memory overhead (Data::Dumper being the worst offender as far as I can tell), MLDBM adds on another 10-20%. The widom to consider SQL is valid. Take a look at DBIx::Recordset for a module that will allow you to work with the your database using native Perl hashes and not have to mess with DBI or SQL ugliness. | [reply] |
Re: Basic Database?
by mr.dunstan (Monk) on Jun 12, 2001 at 02:45 UTC | |
| [reply] |