in reply to Usage of grep on a file

Probably you want to combine Regexp::Assemble with inplace edit and do something like:

use Regexp::Assemble; my $ra = Regexp::Assemble->new; $ra->add ($_) for @matchArray; my $re = $ra->re; @ARGV = ('filename'); $^I = '.bak'; while (<>) { print if m/$re/; }

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Usage of grep on a file
by tsk1979 (Scribe) on Apr 07, 2006 at 07:30 UTC
    Thanks. If I dont want to use that module then do I do this? instead of that I can have
    $full_string = ""; foreach (@match_array) { $full_string = $full_string."|".$_; }
    then do a grep with $fullstring as the match pattern?

      If the file is large don't slurp it, use a loop to process a line at a time. You could do it this way:

      #open file #open outFile while (<file>) { my $line = $_; my $match = 0; for (@matcharray) { ($match = 1), last if $line =~ m/$_/; } print outFile $line if $match; }

      DWIM is Perl's answer to Gödel
      # ... which is same as ... $full_string = join '|' , @match_array;