in reply to Re^9: inserting array of data into text file
in thread inserting array of data into text file

ok, thanks, 1) basically open file "data" which contains 2 columns of numerical data approx 400 lines. Copy this data to another file "complete"
e.g. file "complete" 0 1 1 0 1 0 e.g. file data 0.521 0.365 0.258 0.456 0.211 0.912 so output would be: 0 1 0.521 0.365 1 0 0.258 0.456 1 0 0.211 0.912
thanks,

Replies are listed 'Best First'.
Re^11: inserting array of data into text file
by dragonchild (Archbishop) on Jul 13, 2004 at 20:16 UTC
    So, your basic set of steps is:
    1. Read file1
    2. Read file2
    3. Write file3 with each line from file1 and file2

    What happens if they don't have the same number of lines?

    chomp( my @file1 = do { open FH, (+shift); <FH> } ); chomp( my @file2 = do { open FH, (+shift); <FH> } ); my @file3; while( @file1 && @file2) { push @file3, join(' ', shift(@file1), shift(@file2)); } open FH, ">output"; print FH join($/, @file3, ''); close FH;

    Of course, you're going to want to add some error-handling for the file operations.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested