> Hi all, > can anyone address me to a Perl module/function to parse gzipped log files without uncompressing them via gzip/gunzip? > Thanks > > Mariano >
Compress::Zlib is my standard way to do this. If all you want to do is grep them then zgrep will be faster as the others have pointed out. I don't like shelling out, period, so I would avoid the other (somewhat elegant) solutions offered. The added benefit to using C<gzopen> is that it will work on zipped/unzipped files similar to how zgrep functions. Code I have used below, there should be one more check (at least) to verify that $gz is defined. http://danconia.org -- Untested -- use Compress::Zlib; # # Opens a log file for reading, even if the file is gzipped. gzopen and # gzreadline will read the data if it is regular or gzipped. Returns an # array reference of all of the lines from the file. # sub _read_log { my $self = shift; my $log = shift; my @lines = (); unless (-f $log) { die "Can't open log file '$log' for reading\n"; } my $line; my $gz = gzopen($log, "rb"); while ($gz->gzreadline($line) > 0) { chomp $line; push (@lines, $line); } $gz->gzclose(); return [EMAIL PROTECTED]; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>