Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Best way to store an object collection.

by jeteve (Pilgrim)
on Aug 04, 2005 at 09:23 UTC ( #480737=perlquestion: print w/replies, xml ) Need Help??
jeteve has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks. Here is my quest:

I wish to store a collection of heterogeneous objects under a key name in order to make them persistent. I don't need to query them, I just need to be able to give the key and retrieve the collection. I also like to use a RDMS server as storage backend.

I had a look to *Session* ( like CGI::Session ) or *Cache* (like Cache::FileCache ) but theses storage are dedicated to store temporaly objects so they don't really fit my needs since object destiny is to expire within those storages.

I also had a look at data serializers like Data::Serializer, but it don't seem able to use a database as storage backend.

What would you do you wise monks to cope with that issue ?
Thx !
Nice photos of naked perl sources here !
  • Comment on Best way to store an object collection.

Replies are listed 'Best First'.
Re: Best way to store an object collection.
by davorg (Chancellor) on Aug 04, 2005 at 09:33 UTC
      Wooow, it rocks :)
      Nice photos of naked perl sources here !
Re: Best way to store an object collection.
by knoebi (Friar) on Aug 04, 2005 at 09:43 UTC
Re: Best way to store an object collection.
by SimonClinch (Deacon) on Aug 04, 2005 at 09:34 UTC
    perltie seems appropriate - although the documentation foucuses on tying hashes, scalars and array, don't let this fool you - tie is just as good at tying objects to database entries.

    One world, one people

Re: Best way to store an object collection.
by srdst13 (Pilgrim) on Aug 04, 2005 at 13:54 UTC

    You may want to look at Tie::DBI. If you have a complex data structure associated with each key (a complex hash of hashes, or the like), you can use Storable, Data::Dumper, or YAML to serialize the data structure to text and store that.

    For a more database-centric view of things, look at Class::DBI.


Re: Best way to store an object collection.
by InfiniteLoop (Hermit) on Aug 04, 2005 at 20:59 UTC
      And how does that make the objects persistent?


Re: Best way to store an object collection.
by kwaping (Priest) on Aug 04, 2005 at 23:21 UTC
    Are you talking about storing in RAM or in a file?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://480737]
Approved by blazar
Front-paged by broquaint
[Corion]: ... gets called once. The data structure for that is just a hash of arrays, mapping the event type to a queue of registered one-shots, and the first one-shot from the queue gets removed and called.
[Corion]: But now I want to register a one-shot for two events, of which only one will arrive, so my data structure doesn't work anymore...
[Lady_Aleena]: Corion, ouchy.
[Corion]: (maybe I should write this up as a SoPW) - currently, the "most efficient" data structure I come up with is a single array which I scan for the first fitting one-shot. Not efficient but I don't expect more than five outstanding one-shots anyway
[choroba]: can't you create a meta-key corresponding to the disjunction of the events?
[robby_dobby]: Corion: Heh. This whole thing smells of Strategy Pattern or MVC pattern.
[Corion]: And performance linear to the number of registered one-shots doesn't feel that bad. Maybe I should collect statistics on how many callbacks are outstanding ;)
[Corion]: choroba: Yes, but the longer I thought about efficient hashes mapping the event type back to their callbacks, and how to keep them in sync, the more I thought that all that optimization might just not be worth it, even if it's horribly inelegant
[Lady_Aleena]: My biggest problem with hashes at the moment is one with 2,501 keys.
[choroba]: how many event types are there?

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2017-05-29 07:54 GMT
Find Nodes?
    Voting Booth?