[Classiccity-pm] basic idiot question

Mark Hazen markh at markh.com
Fri Oct 24 19:08:28 CDT 2003


On Fri, 24 Oct 2003, Jeff Scarbrough wrote:

> Today's project is a little more complicated:  I have two or three similar 
> data files from different instruments, and I need to read them all in and 
> output a file where the times recorded in each line match.  It's 

Can you give some examples of what the data looks like?

Basically, what you will want to do is iterate through both files at the 
same time, and parse the time. Read a line from FILE1 and FILE2. If the 
time is equal, output the lines to your output file and read the next line 
from both files. If the time in FILE1 is less than the time in FILE2, read 
another line from FILE1 and compare again. If the time is greater, read 
another line from FILE2, and so forth.

If you can give lines of data as a test, I am sure one of us can write out
a sample of code to handle it. I wouldn't consider this brute force, but
it's the sanest way to handle the problem. If the data includes a date as
well as the time, and is therefore guaranteed to be unique, you *could*
parse one file into a hash using the time+date as the key and the entire
line as the value, then scan the second file, and for every line with a
matching key, delete the element from that hash and write it out to the
output file... but that is so much messier, and requires more memory as
the first file is in size.

Hope this helps straighten out some of the mess...

-mh.
----
   . _+m"m+_"+_    Mark Hazen
 d' Jp     qh qh    
Jp  O       O  O    
Yb  Yb     dY dY 
 O   "Y5m2Y"  "  even the mightiest wave starts out as a ripple.
  "Y_            why make waves when it's easier to nurture ripples?




More information about the Classiccity-pm mailing list