Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Better solution to the code

by hipowls (Curate)
on Jan 25, 2008 at 10:28 UTC ( #664259=note: print w/ replies, xml ) Need Help??


in reply to Re: Better solution to the code
in thread Better solution to the code

Precompiling the regexes should provide a speedup and using List::MoreUtils::any() may do if the chance of a match is good since the test will shortcut on success. Naturally you will benchmark;-)

use List::MoreUtils qw(any); open my $OUT, '>', 'Result_file.txt' or die "Cannot create file: $!\n" +; open my $IN, '<', 'Input_file.dat' or die "Cannot read file: $!\n"; # precompile the regexes. @tag_rx = map {qr/$_/} @tag; while ( my $data = <$IN> ) { print $OUT $data if any { $data =~ /$_/ } @tag_rx; } close $IN; close $OUT;


Comment on Re^2: Better solution to the code
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-04-20 13:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls