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