in reply to Search List

You could use Regex::Assemble to build a big regex from the list. But I would recommend using a hash:
%searchlist = map { $_ => 1 } @searchlist; open(IN,"test.txt"); while (<IN>) { chomp; if ( $searchlist{$_} ) {print "Match Found"} }


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Search List
by Roy Johnson (Monsignor) on Dec 20, 2005 at 16:31 UTC
    Your suggestion would find any matching item on a line by itself. It is not clear from the OP whether the file to be searched is laid out that way. If (as I suspect) it's paragraphs, then it would need to be broken down into words to be checked one-by-one, or they'd need to use your Regex::Assemble solution.

    Caution: Contents may have been coded under pressure.
Re^2: Search List
by patron (Beadle) on Dec 24, 2005 at 16:53 UTC
    Aside from note by Roy Johnson, I would change
    if ( $searchlist{$_} ) {print "Match Found"}
    to
    if ( exists $searchlist{$_} ) {print "Match Found"}
    since your test would add a entry to the hash on each word which isn't there.
    Update: This is wrong, see reply.
      That's wrong. Just looking up a hash key does not autovivfy that key. Consider
      my %h = (); print "found" if $h{somekey}; print %h;
      which prints nothing. The key "somekey" is not autovivied.


      holli, /regexed monk/
        Oh my, You're right! I've always thought that exists() is a ugly exception to the rule, that $hash{key} autovivify ``key'' if it doesn't exist. However, using exists() is more explicit and I think I'll still use it in turbo-clean code. Thanks for enlightenment.