williey
Technical User
- Jan 21, 2004
- 242
Hi,
The script below read a list of text files that meets the wildcard criteria from a directory. It loops through all the files and rewrite to a new file after discarding some records.
For some reason(s), some files are empty. If I were to limit the number of files to process, the output files are successfully written. Is the problem due to filehandle conflicts?
------------------------------------------
There are 10 kinds of people in this world. One that understands binary and the other one that does not.
The script below read a list of text files that meets the wildcard criteria from a directory. It loops through all the files and rewrite to a new file after discarding some records.
For some reason(s), some files are empty. If I were to limit the number of files to process, the output files are successfully written. Is the problem due to filehandle conflicts?
Code:
foreach $file(@files)
{
$outfile=substr($file, 0, length($file) - 4) . ".dat";
print("Processing " . $file . "\n");
print("Output file: " . $outfile . "\n");
open(INFILE, "$file") or die "File does not exist: $file !";
open(TMPFILE, ">$outfile") or die "File does not exist: $outfile !";
while ($line = <INFILE>)
{
if ($line =~ /$pattern/i)
{
if ($set2_found eq 'N')
{
$line3 = substr($line, 0, 44);
print(TMPFILE "$line3");
}
$set2_found = 'Y';
}
if ($set2_found ne 'Y')
{
print(TMPFILE "$line");
}
}
print("Processing completed\n");
# sleep(6);
close (INFILE);
close (TMPFILE);
------------------------------------------
There are 10 kinds of people in this world. One that understands binary and the other one that does not.