Problems? Is your data what you think it is? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
The short answer is "yes you can use DBI with DBD::AnyData to treat your data as a database and run SQL queries on it".
The somewhat longer answer is that you'll want to convert your data from the hash to a text format such as CSV (Comma Separated Values) or XML or a Fixed-length record. AnyData can work with those and others. For the example below, I'll assume you will use CSV. A second issue is the names of your fields. AnyData tries to stick to the rules of SQL which define fieldnames as starting with an alphabetic character and containing only alphanumerics and underscores. There are ways to circumvent that by quoting the field names, but that adds a level of complexity you don't really need. It would be much simpler to rename your fields to be valid SQL field names. I've done that in the example below (e.g. _SESSION_ID loses the underscore and image.x gets an underscore instead of a period). With those caveats, here's a working example that takes a hash like you've shown, inserts it into a database and then queries that database.
There are a couple of perl "tricks" here - I use a hash slice to extract the values from your hash and I use join to create strings of placeholders. In actual practice you probably won't create, insert, and query all in one script (or at least not in the same part of the script) but I've combined them here so you can see the full process. I hope this helps. In reply to Re: dbi::anydata
by jZed
|
|