From: James Edward Gray II Date: 2009-10-22T06:56:58+09:00 Subject: Re: merging partial, incomplete data files On Oct 21, 2009, at 4:20 PM, Benjamin Thomas wrote: > Hello all, Hello. > I write scripts for fun and am still a noob. I don't think I wrote code as good as you when I was new. ;) > I have 2 csv files I'd like to merge such as : > > File1 File2 > ----- ----- > ref;qty ref;price > A;10 A;100 > B;20 D;150 > C;30 C;200 > E;5 B;75 > > outputs to File3 => > > File3 > ----- > ref;qty;price;total > A;10;100;1000 > B;20;75;1500 > C;30;200;6000 > D;"missing_data";150;"missing_data" > E;5;"missing_data";"missing_data" > So I have 2 arrays which is great but I'm not sure on how to go about > merging all this since data is sometimes missing from file1, some > other > times from file2. It's a tricky question. There are a few ways I can't of to do things. First, you could load one giant Hash (indexed by ref) of Arrays or Hashes with the data as you read it, then just dump the Hash to disk. This is the easiest, but it requires you to have all data in memory at once. Are the files small enough that you can do that? James Edward Gray II