Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Search List

by sachmet (Scribe)
on Dec 20, 2005 at 16:27 UTC ( #518110=note: print w/replies, xml ) Need Help??


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/

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://518110]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2021-04-19 05:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?