in reply to storing grep output to variable

You're using the shell utility "grep" by virtue of the backtick quoting - not the perl function "grep" which is similar. Here is is a chunk of perl code that will do a case sensisive grep of a file.

open(IN, $ARGV[0]); @foo = grep { m/$ARGV[1]/ } <IN>; print @foo;

Replies are listed 'Best First'.
Re^2: storing grep output to variable
by Anonymous Monk on Jun 08, 2004 at 18:01 UTC
    Thanks very much everyone! I have gotten the code to work! I went with the following coding:
    my @lines = grep /$prop/, <FILE>;
    This seems to give the result I was looking for, though it's not exactly identical to any of the great solutions you all gave. Anyway thanks for curing my ignorance of grep - at least partially :)
      That's the solution I would use myself. I'd just like to make a note that FILE type filehandles are global. Instead of globals you should use a lexical filehandle: open my $file, '<', $filename or die $!. See perldoc -f my and perldoc perlsub (Private Variables via my()) for an explanation of globals and lexicals.