I’m trying to use the IO::Uncompress::Gunzip module. Per it’s documentation, I should be able to provide an output variable of an array reference to have it push results onto that array (documentation here). When I do the following:
my $blah = [];
gunzip $blah_gz => $blah or die("gunzip failed: $GunzipError\n");
Gunzip just pushes a single scalar containing all the lines of the file onto $blah, essentially treating its first elem as a scalar reference. Am I doing something wrong? Is this a bug? Is it desired behavior? Whatever it is, it’s annoying.
This is doing exactly what it is supposed to be doing. According to the docs, supplying an array reference for the output will uncompress the contents then push it onto the supplied array.
Perhaps what you thought it should do is put the lines of the uncompressed output into your array? If you want something like that do:
Note, the contents will not have the trailing new line, so you don’t need to
chompeach line as you process it, but you will have to usesayor do something likeprint $_, "\n"when you go to print it out.If you are short on memory, and don’t want to essentially keep three copies of your data around, and
$blah_gzand$a_scalar_vararen’t going to drop out of scope (e.g. when you return from the function doing the uncompression), you can add in:after you have
@contentsgenerated.