Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Why is the size even bigger after pack?

by flexvault (Parson)
on Nov 03, 2011 at 13:01 UTC ( #935653=note: print w/ replies, xml ) Need Help??


in reply to Why is the size even bigger after pack?

I read this yesterday, and couldn't understand the question.

This is a guess, but maybe the Title should have been "How do I compress a string variable in perl?"

To compress strings and save memory/disk, you can use the core modules IO::Compress::Gzip and IO::Compress::Gunzip The examples are good, so I don't think you need a code sample. In working with HTML, I have gotten 10x to 20x string reductions. For caching data, that's great!

But what can you do with 'pack/unpack'? -- Lots of great things. These commands greatly reduce the complexity of transferring binary data from big-endian to little-endian machines and vice-versa. And how would you work with 'sockets'/'DNS' etc. without them.

But I just found a new use (for me). I do a lot of work with public/private encryption keys. If the data gets corrupted, you need to generate new keys. Even worse, what if the keys have been changed on purpose.

What I do now is the following ( non-verified code sample ):

use String::CRC32; ## you can use 64 bit as well, but then need to ch +ange pack/unpack functions ## May need to install from CPAN, but has installe +d on all systems I use my $keys = pack( "N N",length( $PublicKey ), length( $PrivateKey ) ) . + $PublicKey . $PrivateKey; my $crc = crc32($keys); my $record = pack("N N", $crc , length($keys) ) . $keys;

Keep a copy of this file on a non Internet connected computer and before the business day starts, the data is verified for accuracy of the keys.

I for one, am glad perl has 'pack/unpack'!

Thank you

"Well done is better than well said." - Benjamin Franklin


Comment on Re: Why is the size even bigger after pack?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935653]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (19)
As of 2014-07-28 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (204 votes), past polls