There are a number of major problems with your code. The first is that you can open REFILE many times, but you only explicitly close it once - that probably indicates a fundamental logic error.
Any code which rereads a file for each line of another file is bound to be slow. Don't do that! Instead read all of the smaller file into memory (if you want to look stuff up put that stuff in a hash) once before you start processing the second file, then make use of the cached data from the smaller file.
Numbered variables almost always indicates that you should be using an array. In this case you could:
my @vars = (undef, $5, $9, $11, $13, $15, $17, $19, $7, $1);
although given that you don't access most of the values in the sample code you may be better to use named variables (with sensible names) for just the fields you do need. You would be even better to not capture the fields you're not interested in and thus simplify your regex!
Ignoring the file management issue for the moment (I don't know how big the files are so it's hard to tell what a sensible solution is), the code can be cleaned up to:
use strict; use warnings; my $file2 = <<FILE2; 00001 003 run1_sub1_event4 FILE2 while (my $line = <DATA>) { next if $line !~ /\S+\s+run\d+_sub\d+_event(\d+)\s+(.*)/; my ($event, $tail) = ($1, $2); my @params = split /\s+/, $tail; open my $DATA2, '<', \$file2 or die "Cannot open file2"; while (my $line2 = <$DATA2>) { next if $line2 !~ /\S+\s+(\S+)\s+run\d+_sub\d+_event(\d+)/; print "$event $params[1] $2\n" if $params[2] == $1 && $params[ +3] == $2; } close $DATA2; } __DATA__ 00001 run1_sub1_event1 1 2 3 4 5 6 7
prints:
1 2 4
In reply to Re: quicker way to merge files?
by GrandFather
in thread quicker way to merge files?
by nessundorma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |