in reply to Question on IO::UnCompress::GunZip...

Multiple lines separated by "\n" would constitute a regular text file; hence, for that I'd do something like this:
#!/usr/bin/perl use strict; use warnings; my $lines = 0; my $filename = '/path/to/tar.gz'; die "Can't open '${filename}': $!" unless open FILE, $filename; while (sysread FILE, my $buffer, 4096) { $lines += ($buffer =~ tr/\n//); } close FILE;

Replies are listed 'Best First'.
Re^2: Question on IO::UnCompress::GunZip...
by biswanath_c (Beadle) on Jan 17, 2010 at 04:21 UTC

    Thanks for the reply Khen! But would a "open FILE...." statement work fine to open a zip file (.gz)? i.e., I can just read the zip file as if it were a normal text file using the very same set of operations/commands?


      Unfortunately, no. The script can count newlines, but opening and reading the zipped file is a different thing altogether.