Re: checking gzip files



On 12/30/05, S Khadar <ibiokid@xxxxxxxxx> 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.
.



Relevant Pages

  • Re: shell function in VB
    ... you are effectively calling Shell as a Sub (no return value ... Now, for your question, the help files show it being appended to the end of ...
    (comp.lang.basic.visual.misc)
  • Re: What happens in procedure 1 the very instant sub procedure 2 is called?
    ... That will be handy to know if there are any dependencies ... that depends entirely on what you're calling code does. ... it will return control back to the original ... >If, for instance, your called MySubmakes a call to Shell() it ...
    (comp.databases.ms-access)
  • Re: calling function without wait
    ... the exeution of the current function waits until the calling ... However if i use shell the function doesn't wait. ... Huh? ... For functions in VBA this is not possible. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Access - Sleep function
    ... For the Sleep command to work while using Shell, the loop that does the ... checking will need to be in VBA, calling Shell each time you loop. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Changing the parend current directory
    ... > Is there any way to make a shell that changes the calling shell's ... what i need is to create a shell script that ... > can change the calling shell's current directory. ... eval `cd-script` ...
    (comp.unix.shell)