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]

Reply via email to