unb0rn has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I've been thinkering some time with the best way to compact a text stream and put into a BerkeleyDB database.

I don't have access to install modules into the server, then I need to find a "purist" perl-way to do the job :]

I tried and could do it with a creation of a temporary file, but I coudn't do with any sort of pipes with gzip, the way I think is better.

What (and how) do you think is the best way to do it?

Tks a lot..

Replies are listed 'Best First'.
Re: (De)Compressing a text stream
by bikeNomad (Priest) on Jul 01, 2001 at 22:44 UTC
    There's no efficient way to compress text streams in pure Perl. Best bet would be to use Compress::Zlib (which is lots better than calling gzip). It wouldn't be too surprising if your installation included it.

    my $compressedData = Compress::Zlib::memGzip($uncompressedData); my $uncompressedData2 = Compress::Zlib::memGunzip($compressedData);

    I don't understand what the problem with "installing modules" is; if you can write to a directory to install your program, you can install the (pieces of the) module to the same directory (in subdirectories) and push the appropriate paths onto @INC. I'm sure there's descriptions elsewhere on PM as to how to do that. Note that Compress::Zlib has got several pieces that will need to be installed:

    /usr/lib/perl5/site_perl/5.6.1/i686-linux/auto/Compress/Zlib
    /usr/lib/perl5/site_perl/5.6.1/i686-linux/auto/Compress/Zlib/Zlib.bs
    /usr/lib/perl5/site_perl/5.6.1/i686-linux/auto/Compress/Zlib/Zlib.so
    /usr/lib/perl5/site_perl/5.6.1/i686-linux/auto/Compress/Zlib/autosplit.ix
    /usr/lib/perl5/site_perl/5.6.1/i686-linux/auto/Compress/Zlib/.packlist
    /usr/lib/perl5/site_perl/5.6.1/i686-linux/Compress/Zlib.pm
    
    Of course, you'd put them in your own directories.