file1.txt
Washington,Louise,Mary,6,H,193 First St.
Washington,Ann,Carla,1,C,187 10th St.
file2.txt
Child,28,209-568-5177
file1 includes: last name,middle name, first name,# of children,parent code,address
file2 includes: child,age,address
What I'm trying to do is read line one of the file1.txt file if parent code is 'H' then I print that line as is but if parent code is 'C' then I include the information from file1 and go to file2 and retrieve that information for the child which is in the file2 file. So what my output looks like is:
Washington,Louise,Mary,6,H,193 First St.
Washington,Ann,Carla,1,C,187 10th St.,Child,28,209-568-5177
I have to go back to file1 which has infinite number of lines of data and read it and go to file2 only when it's a child and get that information to add to file1. | [reply] |
He meant show us the code...
My guess, even without the code, is that you are re-opening the same handle. You'll want to use a different handle for your second file. I.e. if your first open is something like open(FOO, "<file.txt") the next open shouldn't reuse FOO.
-sauoq
"My two cents aren't worth a dime.";
| [reply] |
open(STDIN, "ICD_MEAS.txt")
or die "Cannot open file";
@row = <STDIN>;
$done = 0;
$count = 0;
while (@row[$done])
{
chop(@row);
foreach (@row[$count])
{
@column = split(/\,/,@row[$count]);
$last_name = @column[0];
$middle_name = @column[1];
$first_name = @column[2];
if ($source_type =~ /H/)
{
print ("$sat_name;");
print ("$meas_name;");
print ("$first_name;");
}
if ($source_type =~ /C/)
{
open(STDIN1, "ICD_MEAS_child.txt")
or die "Cannot open file";
@row = <STDIN1>;
$done = 0;
$count = 0;
while (@row[$done])
{
chop(@row);
foreach (@row[$count])
{
@column = split(/\,/,@row[$count]);
$status = @column[0];
$age = @column[1];
$address = @column[4];
print ("$sat_name;");
print ("$meas_name;");
print ("$first_name;");
print ("$status;");
print ("$age;");
print ("$address;");
}
}
}close STDIN1;
count++;
}
done++
}close stdin;
I don't know what I'm doing wrong b/c the first line is the H so it prints the first line stuff, the second line is a C so it prints the new file stuff and the first file, but wont go back to the first file to get the next line of data so I could see if it's a H or C. It doesn't loop back.
2003-05-28 edit ybiC <code> tags
| [reply] [d/l] |