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

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.

If the reasoning behind the hex representation is to make it "safe" to treat this data in certain ways (such as transmitting on usenet) that might lose control characters and anything over seven bits, then it's possible to do better by using a base larger than 16, but smaller than 256. For example, if you use base 64 with 33 added to each digit when mapping it back into ASCII, you get all nice safe printable characters but manage to store six usable bits in every byte, which is not altogether bad. If you can get better than 25% compression, you'll have a net gain (though perhaps not a large one). On English text of any significant size, better than 25% gain is very achievable with a simple Huffman tree, much less gzip.


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/