First we would have to answer WHY we would want to pack a hash (You probably meant 'pack' as in 'compress' or 'zip', right? The perl function pack has a different purpose than compression).

It would have the following advantage:

1. You could keep those few applications unchanged that are so big that they don't fit into memory anymore but that would still fit if compressed by about 5 to 50% (the usual compression rate of general compression algorithms, assuming you even could reach that with a hash compression, which is very doubtful). Most people would tell you to buy more RAM instead or adapt your algorithm/data structure

... and the following disadvantages

1. A compressed hash isn't a hash anymore, before accessing it you would have to uncompress it. You couldn't use $hash{'bla'} anymore. So you add a lot of inconvenience to the handling of hashes for the programmer

2. Uncompressing takes time. More than the time it takes to access a hash, so we are talking about a speed penalty of more than 100%. For a few free bytes more the hashes are seriously slower now.

3. Compressing algorithms don't guarantee compression. So even if you had a program that just needed 5% compression to fit into memory you never could be sure that your compressed hash could deliver it. With the "wrong" data your compression rate could be 0.

4.


In reply to Re: Packing hashes or complex structures? by jethro
in thread Packing hashes or complex structures? by theantler

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.