August 1999 Return to the Perl Hardware Store Slide #31

Iterator Example

        sub locate {
          my ($key, $file) = @_;
          local *FH;
          open FH, $file or return;
          my @result;
          while (<FH>) {
            push @result, $_ if index($_, $key) >= 0;
          }
          @result;
        }


Next Copyright © 1999 M-J. Dominus