File Coverage

examples/io/gzip/gzgrep
Criterion Covered Total %
statement 18 18 100.0
branch 6 10 60.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 27 31 87.1


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 1     1   5875 use strict ;
  1         3  
  1         45  
4 1     1   6 use warnings ;
  1         2  
  1         61  
5 1     1   764 use IO::Uncompress::Gunzip qw($GunzipError);
  1         4  
  1         1924  
6              
7 1 50       182405 die "Usage: gzgrep pattern [file...]\n"
8             unless @ARGV >= 1;
9              
10 1         4 my $pattern = shift ;
11 1         3 my $file ;
12              
13 1 50       3 @ARGV = '-' unless @ARGV ;
14              
15 1         3 foreach $file (@ARGV) {
16 2 50       57 my $gz = new IO::Uncompress::Gunzip $file
17             or die "Cannot uncompress $file: $GunzipError\n" ;
18              
19 2         14 while (<$gz>) {
20 15 100       168 print if /$pattern/ ;
21             }
22              
23 2 50       16 die "Error reading from $file: $GunzipError\n"
24             if $GunzipError ;
25             }
26              
27             __END__
28             foreach $file (@ARGV) {
29             my $gz = gzopen($file, "rb")
30             or die "Cannot open $file: $gzerrno\n" ;
31              
32             while ($gz->gzreadline($_) > 0) {
33             print if /$pattern/ ;
34             }
35              
36             die "Error reading from $file: $gzerrno\n"
37             if $gzerrno != Z_STREAM_END ;
38              
39             $gz->gzclose() ;
40             }