http://qs1969.pair.com?node_id=597091


in reply to search for a pattern in file without opening the file

If you don't want to open the files in your code you could use a system call.
my $success = ( system("grep $searchpat $file >/dev/null") ) ? 0 : 1;
as long as its a simple pattern.
Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson

Replies are listed 'Best First'.
Re^2: search for a pattern in file without opening the file
by Anonymous Monk on Oct 30, 2018 at 00:42 UTC
    If the grep finds a match it returns 0 or 1?

      Yes, as explained in the Exit Status section of the man page.