If you convert ASCII text with say 80 used chars into gzipped hex where you effectively drop yourself down to a 16 char alphabet but still in the (extended) ASCII 8 bit space you need 5x compression just to break even. This is close to the max compression you expect with gzip on text so this is kinda pointless. Normally you pack your ~ 80 char alphabet into a 256 slot 8 bit binary space. This is where a significant part of the compression comes from - using all the available bits efficiently. Hex is not the go.

[root@devel3 root]# cat test.pl #!/usr/bin/perl use Compress::Zlib; my $str = "Hello World!"; my $gzip = Compress::Zlib::memGzip( $str ); my $hex_enc = unpack 'H*', $gzip; my $hex_dec_gzip = pack 'H*', $hex_enc; my $str_dec = Compress::Zlib::memGunzip( $hex_dec_gzip ); print " $str $hex_enc $str_dec "; [root@devel3 root]# ./test.pl Hello World! 1f8b0800000000000003f348cdc9c95708cf2fca49510400a31c291c0c000000 Hello World! [root@devel3 root]#

cheers

tachyon


In reply to Re: reversible pack()? by tachyon
in thread reversible pack()? by monsieur_champs

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.