in reply to Re: reversible pack()?
in thread reversible pack()?

So I need a better approach to achieve compression enought to get trought the break-even. Any suggestions? Maybe I should leave the gzipped string as is, and hope no distortion can happen while editing the uncompressed part of the program?

Can you point me some nice website or good book about this matter?

Thank you very much again!


"In few words, translating PerlMonks documentation and best articles to other languages is like building a bridge to join other Perl communities into PerlMonks family. This makes the family bigger, the knowledge greater, the parties better and the life easier." -- monsieur_champs

Replies are listed 'Best First'.
Re: Re: Re: reversible pack()?
by tachyon (Chancellor) on Feb 11, 2004 at 13:49 UTC

    gzip first then base64 encode. To decode undo in opposite order ie base64_decode then gunzip. Still a lot fatter than binary but a lot thinner than hex.

    If you want to know something try Google. There are hundreds of websites dealing with compression. Try say 'tutorial data compression theory' and find sites like......why don't you have a look yourself.

    It is trivial to test this. Just compress, encode a representative string, and check it for LENGTH. Repeat with another encoding. Compare to length of gzip string and you will see how much you are loosing.

    use Compress::Zlib; use MIME::Base64; my $str = "Hello World! " x 3; my $gzip = Compress::Zlib::memGzip( $str ); my $hex = unpack 'H*', $gzip; my $base64 = encode_base64('Aladdin:open sesame'); my $str_len = length($str); my $gzip_len = length($gzip); my $hex_len = length($hex); my $base64_len = length($base64); # make binary printable ;-) $gzip = '#' x $gzip_len; printf "%3d: %s\n%3d: %s\n%3d: %s\n%3d: %s\n", $str_len, $str, $gzip_len, $gzip, $hex_len, $hex, $base64_len, $ba +se64; __DATA__ 39: Hello World! Hello World! Hello World! 36: #################################### 72: 1f8b0800000000000003f348cdc9c95708cf2fca495154f0c0c90100b9a8ae382 +7000000 29: QWxhZGRpbjpvcGVuIHNlc2FtZQ==

    You will see the value of compression as you increaase the string length.

    cheers

    tachyon