Try using
Compress::Zlib . Once compressed, you'll probably want to base64 encode them. This will increase the size of your zip by 4/3, but will allow you to store 'binary' data on the cookie.
use Compress::Zlib ;
use Storable ;
my %hash = &some_data ;
my $data = pack( "u*",
Compress::Zlib::MemGzip( freeze \%hash) ) ;
# now you can do as you please with $data
# to unthaw:
my $hashref = thaw( Compress::Zlib::MemGunzip(
unpack( "u", $data ) ) ) ;
You'll also want to carefully manage the variables you need stored, as cookies tend to allow a minimal amount of space.
Update: GrandFather is absolutely right, though. The best way to store the data is on the server. This method will work, if you're insistent.
Another Update: I've been thinking about this, and I strongly advise you not to do it.
If you give a variable to a user, that user may choose to unpack, unzip, and thaw it. Then that user could look at your data structure and do something to the cookie ( for example, set $data{'user'} = 'admin' ) and send it back to you. This could be disastrous.
Peace monks,
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.