summaryrefslogtreecommitdiff
path: root/ext/IO-Compress/examples/io/gzip/gzgrep
diff options
context:
space:
mode:
Diffstat (limited to 'ext/IO-Compress/examples/io/gzip/gzgrep')
-rwxr-xr-xext/IO-Compress/examples/io/gzip/gzgrep40
1 files changed, 40 insertions, 0 deletions
diff --git a/ext/IO-Compress/examples/io/gzip/gzgrep b/ext/IO-Compress/examples/io/gzip/gzgrep
new file mode 100755
index 0000000000..33820ba064
--- /dev/null
+++ b/ext/IO-Compress/examples/io/gzip/gzgrep
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+use strict ;
+use warnings ;
+use IO::Uncompress::Gunzip qw($GunzipError);
+
+die "Usage: gzgrep pattern [file...]\n"
+ unless @ARGV >= 1;
+
+my $pattern = shift ;
+my $file ;
+
+@ARGV = '-' unless @ARGV ;
+
+foreach $file (@ARGV) {
+ my $gz = new IO::Uncompress::Gunzip $file
+ or die "Cannot uncompress $file: $GunzipError\n" ;
+
+ while (<$gz>) {
+ print if /$pattern/ ;
+ }
+
+ die "Error reading from $file: $GunzipError\n"
+ if $GunzipError ;
+}
+
+__END__
+foreach $file (@ARGV) {
+ my $gz = gzopen($file, "rb")
+ or die "Cannot open $file: $gzerrno\n" ;
+
+ while ($gz->gzreadline($_) > 0) {
+ print if /$pattern/ ;
+ }
+
+ die "Error reading from $file: $gzerrno\n"
+ if $gzerrno != Z_STREAM_END ;
+
+ $gz->gzclose() ;
+}