http://qs1969.pair.com?node_id=935653


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