in reply to Re^2: Read bzip2 directly into array
in thread Read bzip2 directly into array

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.

Replies are listed 'Best First'.
Re^4: Read bzip2 directly into array
by prescott2006 (Acolyte) on Apr 03, 2012 at 11:05 UTC
    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.