open(FILE, $data_file) or die("cannot open file : $!"); print "

opened file $data_file ok\n"; $a = 0; while ($line = ) { $a++; #record every thousand lines as way to check progress if ($a % 1000 == 0) { open(pFILE, '>>progress.txt') or die("cannot open progress file : $!"); print pFILE ", $a"; close(pFILE); } #parse the line @line = split(//, $line); my $line_id = join('', $line[6], $line[7], $line[8]); if ($line_id eq $target_line_id) { my $respondent = join('', $line[0], $line[1], $line[2], $line[3]); # if this line meets the criteria if (($line[$col_1 - 1] eq $value_1) && ($line[$col_2 - 1] eq $value_2)) { $file = ">>".$data_dir."/t".$rid; #record this respondent in a text file open(rFILE, $file) or dienice("cannot open file : $_[0] $!"); print rFILE "$respondent\n"; close(rFILE); # output progress to browser print ", $respondent"; } } } close(FILE);