Sorry I don't have the book (sure wish I did though) but I'll give it a swing.

If we are talking about an SQL database, you have what looks like a row ("record") of separate data fields, with one row for each CD, and if I understand your question correctly, a column Title which is designated the primary key, and a column CdObj which contains a serialized data structure.

The database does the looping for you, and you are just concerned with checking to see if there is already a row which contains a Title field of that name. If your SELECT query does not return any data, you are safe.

If you are not using a database but just writing to disk, It is probably a similar problem. You need not load every object, just your index. Maybe you have it in a separate file from all those big objects and it can be easily loaded into a hash. If so you don't need to loop, just look to see if your hash key exists and if not (so long as they all got read in correctly), you are safe.

Unpacking objects one at a time and looking inside each one would be a terribly slow way to search a database. Much better to let Perl or SQL "look" at a whole column at a time for you and not call all that disk use and computing overhead. I don't understand why you need to serialize an object at all actually, it would seem to be much more interesting to have a separate database field for every part of the object, so you could search by singer, track length, genre, etc. Does this answer the question? If not please try to explain a bit more, thanks.


In reply to Re: handling Perl Persistent Objects by mattr
in thread handling Perl Persistent Objects by rgatliff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.