home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libio-compress-zlib-perl / examples / gzgrep < prev    next >
Encoding:
Text File  |  2008-02-18  |  796 b   |  41 lines

  1. #!/usr/bin/perl
  2.  
  3. use strict ;
  4. use warnings ;
  5. use IO::Uncompress::Gunzip qw($GunzipError);
  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::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__
  28. foreach $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. }
  41.