in reply to Efficient hash storage?

Storable will take up less space in the DB (and it supports nested structures and just about everything else you throw at it.) Its output is not human-readable, though. It is probably not as fast as split for a simple hash, but you should Benchmark to find out what works best.

YAML is fairly space-efficient and easily readable and editable by a human, though it does require lots of whitespace, which may not be appropriate for your database design.

Data::Dumper will spit your structures out in native Perl code, which is can be retrieved from the database and evaled. It is a security risk, depending on who has access to your database. Once you're evaling stuff, you can put any code in there.

Replies are listed 'Best First'.
Re^2: Efficient hash storage?
by whohasit (Novice) on Jul 08, 2005 at 06:16 UTC
    Thanks for your fast response.

    So, I was concerned about Data::Dumper for the reason you outline above.. (and I've never used 'eval' for roughly the same reason that I don't own a TV or a Playstation).

    Are you suggesting YAML is the faster solution (faster than split)?

    I recognize that there are different tools for different jobs but is there any consensus on a simple, portable method for effecient storage ("freeze/thaw") of session hashes that remain mostly read-only?

    Thanks again,

      Define 'mostly' read-only.

      From the sounds of things for what you're doing, you're basically making a configuration file of some sort, so you might want to look through CPAN for 'config'

      I'm currently using a mix of different styles -- XML, unix-esque (key=value), and tab deliminated tables, even within the same project.

      Every situation has slightly different needs, and each method serves a different set of needs. (eg, I'm using XML on stuff that has a heirarchical relationship, with a potential for null or multiple values for some attributes (of which the attributes may be added to later), and may be used in completely other programs, not necessarily written in perl; key=value pairs for items that are a flat list, and don't have multiple values; tab delim tables for records with a fixed number of non-null attributes)