On Thu, Oct 17, 2002 at 11:27:43AM -0400, [EMAIL PROTECTED] wrote: > I have working code which opens two files (1 read, 1 write), then parses > the text from the file FIRSTIN to a particular format, then prints it to > the FIRSTOUT file. > > I need to add to this the capability to open SECONDIN line for line with > FIRSTIN, and just print the same thing I took from SECONDIN to SECONDOUT, > along with a couple of pieces of data I have parsed from FIRSTIN. > > I hope I have explained this well enough.
You did, but you don't mention what should happen when one of the input filehandles reaches EOF before the other, or if that's possible. The solution I would use would go something like this: while (1) { my $first_in = <FIRSTIN>; last unless defined $first_in; my $second_in = <SECONDIN>; last unless defined $second_in; print FIRSTOUT "$first_in\n"; print SECONDOUT "$second_in, $first_in\n"; } The loop stops when EOF is reached in either filehandle; you may want to stop it only when it's reached in both handles, or in one of the handles only. Your code example didn't chomp your input, so I didn't add that in mine; if $first_in and $second_in aren't chomped there will be double newlines in FIRSTOUT and SECONDOUT, as well as a newline between $second_in and the comma after it. You'll probably need to fix that. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]