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

Hi Monks, I am supposed to get a compressed xml string from a server by LWP.
Now i want to decompress it using the Compress::Zlib module.

For doing a simple test i tried to first compress a big string and then decompressing it using this i found on the cpan documentation page for the module.


use Compress::Zlib; my $str_to_compress='a big string'; $compressed_str=compress($str_to_compress[,1]); #original syntax on cpan for the two functions #$dest = compress($source [, $level] ) ; #$dest = uncompress($source) ; $decompressed_str=uncompress($compressed_str); print $decompressed_str;

but when i try to run it it says wrong syntax.
please tell me the correct syntax or any other method to do it.

Replies are listed 'Best First'.
Re: decompressing the string
by Joost (Canon) on Jun 24, 2006 at 13:29 UTC
    I think you misunderstood the [, $level] part of the docs: it's intended to mean that the ", 1" part is optional. As you wrote it it simply won't compile.

    syntax error at test.pl line 3, near "[," Execution of test.pl aborted due to compilation errors.
    Try this:
    use Compress::Zlib; my $str_to_compress='a big string'; $compressed_str=compress($str_to_compress,1); $decompressed_str=uncompress($compressed_str); print $decompressed_str;

    By the way, please note exact error message text next time. Paraphrasing errors will only confuse people.