Move IO::Compress from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / IO-Compress / examples / io / gzip / gzgrep
CommitLineData
25f0751f 1#!/usr/bin/perl
2
3use strict ;
4use warnings ;
5use IO::Uncompress::Gunzip qw($GunzipError);
6
7die "Usage: gzgrep pattern [file...]\n"
8 unless @ARGV >= 1;
9
10my $pattern = shift ;
11my $file ;
12
13@ARGV = '-' unless @ARGV ;
14
15foreach $file (@ARGV) {
16 my $gz = new IO::Uncompress::Gunzip $file
17 or die "Cannot uncompress $file: $GunzipError\n" ;
18
19 while (<$gz>) {
20 print if /$pattern/ ;
21 }
22
23 die "Error reading from $file: $GunzipError\n"
24 if $GunzipError ;
25}
26
27__END__
28foreach $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}