in reply to Re: reading zipped bzipped files!
in thread reading zipped bzipped files!

Here is a variation on a theme that prints the forst 5 lines of each member in the zip file. The difference with this one is that the complete bzip2 file doesn't need to be read into memory.
use strict; use warnings; use IO::Uncompress::Unzip qw($UnzipError); use IO::Uncompress::Bunzip2; my $zipFile = q{mans.zip}; my $zip = IO::Uncompress::Unzip->new( $zipFile ) or die "Cannot open $zipFile: $UnzipError"; my $status; for ($status = 1; $status > 0; $status = $zip->nextStream()) { my $name = $zip->getHeaderInfo()->{Name}; warn "Processing member $name\n" ; my $bzFH = IO::Uncompress::Bunzip2->new($zip); my $lineCt = 0; while ( my $line = <$bzFH> ) { last if $lineCt ++ > 5; print $line; } }

Replies are listed 'Best First'.
Re^3: reading zipped bzipped files!
by johngg (Canon) on Dec 22, 2012 at 12:44 UTC

    Excellent ++

    I was trying to come up with a way which avoided reading the whole bzipped file but I am not familiar yet with these IO::Compress/Uncompress::* modules as most of my work is on servers running 5.8.x or older and I had only used Archive::Zip before. I will have to study.

    Thank you for showing me this method :-)

    Cheers,

    JohnGG