try this full code
$|=1; #*********************** Set auto Flush #*********************** Operning and Locking files if u use in non multiuser environment ignore flock commands open(FIRSTIN,"<infile01.ext"); open(SECIN,"<infile02.ext"); flock(FIRSTIN,LOCK_SH); flock(SECIN,LOCK_SH); open(FIRSTOUT,">out01.ext"); open(SECOUT,">out02.ext"); flock(FIRSTOUT,LOCK_EX); flock(SECOUT,LOCK_EX); #***************************** Following loop will exit when all the lines in boath files are read $read=1; while ($read){ $read=0; if ($in = <FIRSTIN>){ print FIRSTOUT "$in"; $read=1; } if ($in = <SECTIN>){ print SECOUT "$in"; $read=1; } } #****************************** Closing and unlocking files files if u use in non multiuser environment ignore flock commands flock(FIRSTOUT,LOCK_UN); close(FIRSTOUT); flock(SECOUT,LOCK_UN); close(SECOUT); flock(FIRSTIN,LOCK_UN); close(FIRSTIN); flock(SECIN,LOCK_UN); close(SECIN); ----- Original Message ----- From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Friday, October 18, 2002 9:55 PM Subject: Re: How can I open and read two files at once in a loop? > In my case, both files had an equal number of lines. The both contained > comma-separated values to be imported into database tables. One table > needed two additional fields which were contained in the second table. I > had intended on opening both and appending the two fields I wanted. > > In the end, I avoided doing this manually and executed a SQL 'UPDATE' query > on the database to fill in the two fields, after importing both .csv files. > Thanks for all the insight, though. Every time you guys answer a question, > you throw in some interesting snippets which are very helpful to a beginner > like me. > > Shawn > > > > > > [EMAIL PROTECTED] > g To: [EMAIL PROTECTED] > cc: > 10/17/2002 bcc: > 06:49 PM Subject: Re: How can I open and read two files at once in a loop? > > > > > > > Michael Fowler wrote: > > > > 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. > > If you want to stop at EOF you should test for EOF. :-) > > while (1) { > my $first_in = <FIRSTIN>; > last if eof( FIRSTIN ); > > my $second_in = <SECONDIN>; > last if eof( SECONDIN ); > > print FIRSTOUT "$first_in\n"; > print SECONDOUT "$second_in, $first_in\n"; > } > > > > John > -- > use Perl; > program > fulfillment > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > ********************************************************************** > This e-mail and any files transmitted with it may contain > confidential information and is intended solely for use by > the individual to whom it is addressed. If you received > this e-mail in error, please notify the sender, do not > disclose its contents to others and delete it from your > system. > > ********************************************************************** > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]