![]() |
|
Don't ask to ask, just ask | |
PerlMonks |
Re: {4} Encoding/compress CGI GET parametersby jeroenes (Priest) |
on Jan 17, 2001 at 21:36 UTC ( #52555=note: print w/replies, xml ) | Need Help?? |
Hi snellm,
I think this is fun. What you actually need to do, is to represent your data into just the bits that you need, and hack these bits into 8-bits chunks (aka bytes), and transform these bytes into usable characters. This sounds like UUencoding. However, UUencoding uses too many characters.
CPAN sayz: Convert:UU
Hmm.. I see this package just uses pack("u",$string) internally. Well, the search continues. It is obvious that I haven't used pack before! Let's play a little bit. Maybe you want 16 different modes, and 2 16 bit integers for your Area cq Subarea. That adds up to 36 bits (2**4=16). If we use A..Za..z0..9 *and* '%', '-' we have 64 possibilities, or 6 bit. Than we can cram everything in 6 characters. The encoder must pack the stuff: Some reverse coding for the decoder, but I'm too lazy for that. Is this what you want to do? Disclaimer: This is my first use of pack, so I'm not sure I'm doing the right thing, let alone the efficient thing. Please correct me! Cheers, Jeroen Update: Made the decode sub as well. Tested it. Discovered some differences between running at linux and at mac at home, so used 'v' for packing stuff. Now I've moved this code into a module, for generalized use. You can find it here.
In Section
Seekers of Perl Wisdom
|
|