On 12/30/05, S Khadar <[EMAIL PROTECTED]> wrote:
> #!/usr/bin/perl
> use Shell;
...
> $dmchk=zless(  "$dir/$_/foo.gz");

As an aside note, C<perldoc Shell> advises against this style [ use
Shell <nothing> ; ]. Prefer this:

          use Shell qw(zless);

so that you know that you are not calling some program by mistake/typo.

>From the man page of gzip, the command

          zcat $gzfile | wc -c

is recommended to get the uncompressed file size.

You can use it in backticks, like `zcat $gzfile | wc -l` and then
check the returned number.
But this is rather expensive for large files, since you just want to
know if it has zero bytes or not. Ah, you can use 'zcat' where you are
using 'zless' with the same effect but without a pipe to the unix
command 'less'.

A pure Perl solution would be to use Compress::Zlib (which you
probably has already - for example if you use CPAN) and use a function
like

use Compress::Zlib;

sub zz {
    my $f = shift;
    my $gz = gzopen($f, 'r') or die; # error handling left as an exercize
    return ! $gz->gzread(my $buf, 1); # just one or zero bytes read and dumped
                                                    # only return
matters - true for empty, false otherwise
}

my $f = 'a.gz';
print zz($f) ? 'zero bytes' : 'non-empty';

In this case, no need anymore for "use Shell", unless you use some
other external utility.

Regards,
Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to