summaryrefslogtreecommitdiff
path: root/ext/IO-Compress/examples/io/gzip/gzgrep
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-05-05 12:09:48 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-05-05 12:18:11 +0200
commit9de654f174a7c7ca88031e2ac4a33add560d0c8c (patch)
tree7763181344f0e6240e96c5a444c8a5b57c986dc8 /ext/IO-Compress/examples/io/gzip/gzgrep
parentf1bef09e9115ebdc1c8818193d6c4cbb8bc050e6 (diff)
parent216e7dec1076aa94d5b8331c187c135e4952955a (diff)
downloadperl-9de654f174a7c7ca88031e2ac4a33add560d0c8c.tar.gz
Merge branch 'blead' into smartmatch
Conflicts: t/op/switch.t
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() ;
+}