in reply to Search List

If your test.txt file is long, it may make sense to pre-compile the entries for faster searching. Also, you want to make sure to use \Q and \E to make sure wildcards in the file names don't get expanded.

Also, please check return codes on system calls such as open().

Consider something like the following:
my @patterns; foreach my $pattern (`ls`) { chomp $pattern; push @patterns, qr/\Q$pattern\E/; } open(IN,"test.txt") or die "Can't open test.txt: $!\n"; while(my $line = <IN>) { chomp $line; foreach my $pattern (@patterns) { print "Match found\n" if $line =~ $pattern; } }

Replies are listed 'Best First'.
Re^2: Search List
by holli (Abbot) on Dec 20, 2005 at 18:25 UTC
    Or even
    print "mf" if grep { $line =~ $_ } @patterns;
    instead of
    foreach my $pattern (@patterns) { print "Match found\n" if $line =~ $pattern; }


    holli, /regexed monk/