Change 27380 (HEK into the IV union failed to convert the code in the
[p5sagit/p5-mst-13.2.git] / ext / Compress / Zlib / examples / gzgrep
CommitLineData
642e522c 1#!/usr/bin/perl
f4c6fd49 2
3use strict ;
8aa25532 4use warnings ;
642e522c 5use IO::Uncompress::Gunzip qw($GunzipError);
f4c6fd49 6
642e522c 7die "Usage: gzgrep pattern [file...]\n"
8 unless @ARGV >= 1;
f4c6fd49 9
10my $pattern = shift ;
f4c6fd49 11my $file ;
12
642e522c 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__
f4c6fd49 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}