Next Trivial Utilities 77

pgrep: do_file

        sub do_file {
          my $file = shift;
          my $fh;
          if (ref $file) {
            $fh = $file;
            $file = "<stdin>";
          } else {
            return if -d $file;
            unless (open $fh, "<", $file) {
              warn "Couldn't open '$file': $!; skipping\n";
              return;
            }
          }
          while (<$fh>) {
            chomp;
            if (/$qr/ ^ $opt_v) {
              $rc = 0;                  # match
              printf $format, $file, $_, $.;
              return if $opt_l;
            }
          }
        }


Next Menu Copyright © 2012 M. J. Dominus