in reply to Read bzip2 directly into array

The only thing i see here not working is the undefined @apple if i put anything in it i get the output. Use Data::Dumper package to see if the things you think are in the $buffer are really there and in the right place.

cheers

baxy

Replies are listed 'Best First'.
Re^2: Read bzip2 directly into array
by prescott2006 (Acolyte) on Apr 03, 2012 at 08:35 UTC
    @apple has nothing to be defined, it is used to store the content of the text from bz2. The content in $buffer will be pushed into @apple, as mentioned in the doc page. But I wonder why it just doesn't work.
      use Data::Dumper; use strict ; use warnings ; use IO::Uncompress::Bunzip2 qw(bunzip2 $Bunzip2Error) ; use IO::File ; my $input = new IO::File "<tmp.bz2" or die "Cannot open 'tmp.bz2': + $!\n" ;; my $buffer; bunzip2 $input => \$buffer or die "bunzip2 failed: $Bunzip2Error\n +"; print $buffer; foreach ($buffer) { print Dumper($_);; }
      This works for me. Why do you need to have an @array defined (by the way i suppose it is defined somewhere else in the code!!). But even then i don't think it is a problem with bzip because if U are getting the output in print $buffer of print @{$buffer} then the problem must be somewhere else in the code. use Data::Dumper to check what is going on at each step in your foreach line.

        I would like to read each line of the text in .bz2 and pattern matching them with some keyword. But the problem with your code is the foreach loop only run once. That's why I thought want to store them in an array and use foreach to loop through all of the elements. But I don't know how to integrate the array as the output of the bzip2.