Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Better solution to the code

by Punitha (Priest)
on Jan 25, 2008 at 09:53 UTC ( #664254=note: print w/replies, xml ) Need Help??


in reply to Better solution to the code

Hi, try this

open(FH1,"+>Result_file.txt") or die "Cannot create file $!\n"; open(FH,"<Input_file.dat") or die "Cannot read $!\n"; while(<FH>) { my $data=$_; chomp($data); print FH1 "DATA:$data\n" if(grep/$data/,@tag); } close(FH);

Punitha.

Replies are listed 'Best First'.
Re^2: Better solution to the code
by hipowls (Curate) on Jan 25, 2008 at 10:28 UTC

    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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://664254]
help
Chatterbox?
[james28909]: howdy, could a kind monk help me test connectivity to my ftp server? i cannot connect to it from within my home network behind a public ip (i have a dynamic ip) and just need to make sure users can connect.
[james28909]: oh nevermind, i see one of the users in the list of connected users now. thanks!

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-07-27 14:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (416 votes). Check out past polls.