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

At this point, I'm going to stop trying to read your mind. If you want me to help further, you will need to provide the following:
  1. A set of unambiguous requirements describing exactly what this program is supposed to do
  2. A set of example inputs
  3. A set of expected outputs

No code. Just those documents.

------
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

  • Comment on Re^9: inserting array of data into text file

Replies are listed 'Best First'.
Re^10: inserting array of data into text file
by Anonymous Monk on Jul 13, 2004 at 20:03 UTC
    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,
      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