in reply to zlib compression of numeric values

If you want a number output in binary format you need to pack it first, like this (assuming you want it stored as a 32-bit value)

$num_data = pack("V", 7);

Here is a quick proof of concept that compresses a series of strings, each prefixed by a length, then uncompresses them. No error handling is included. The compressed data is stored in a string ($outBuffer) in this example, but it can also work with files with a small modification to the code.

use IO::Compress::Deflate qw(:all); use IO::Uncompress::Inflate qw(:all); sub put { my $handle = shift ; my $string = shift; print $handle pack("V", length $string) , $string ; } sub get { my $handle = shift ; my $buf ; read($handle, $buf, 4) == 4 or return undef ; my $len = unpack("V", $buf); read($handle, $buf, $len); return $buf; } my $outBuffer ; my $out = new IO::Compress::Deflate \$outBuffer; put($out, "hello world"); put($out, "goodbye"); $out->close ; my $in = new IO::Uncompress::Inflate \$outBuffer; my $got ; while (defined ($got = get($in))) { print "$got\n" ; }