in reply to Questions about Grep

If you want to grep a file in Perl, you can read it into an array first:
use strict; open my $fh, "file.txt" or die "Error opening file.txt: $!"; my @lines = <$fh>; my @matches = grep /pattern/, @lines;
There's also the File::Grep module from CPAN which provides some easy-to-use file grepping functionality.

Replies are listed 'Best First'.
Re^2: Questions about Grep
by pc88mxer (Vicar) on May 29, 2008 at 19:14 UTC
    Don't know if this is any more efficient, but it's a few less keystrokes:
    use strict; open my $fh, "file.txt" or die "Error opening file.txt: $!"; print grep /pattern/, <$fh>;
Re^2: Questions about Grep
by Anonymous Monk on May 29, 2008 at 19:23 UTC
    Thanks!