in reply to Re: Usage of grep on a file
in thread Usage of grep on a file

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?

Replies are listed 'Best First'.
Re^3: Usage of grep on a file
by GrandFather (Saint) on Apr 07, 2006 at 07:37 UTC

    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
Re^3: Usage of grep on a file
by parv (Parson) on Apr 07, 2006 at 07:34 UTC
    # ... which is same as ... $full_string = join '|' , @match_array;