How would you do this in Perl?

Bes

Bes

Soldato
Joined
18 Oct 2002
Posts
7,318
Location
Melbourne
Hi

I need to write a script that reads through x log files that look like this:

<Date><Time> <Data>

I need to merge the log files together so that I get something like this in a 2D array:

<Epoch value> <data_file1> <data_file2> <data_file3> <data_file4> etc etc <total (All data_file values for that epoch value added together- this one doesnt have to be in the array but is ultimately what I want.>

Now writing the code should be easy but conceptually, I cannot figure out how I would get everything into a nice array (i.e. I have to open each file, read everything out into my script, match up the times, and have a single array with everything).

The thing is the number of data files can change, and I need to write the script in a way that will allow it to always maintain the above structure.

Any psuedo code anyone can write to help me would be appreciated :)

Thanks
 
If you've unique timestamps as part of the dataset then you could look at using hashes keyed to those. I've not written any Perl for a while, but it's usually because of the extra data structures over bash that I do. It usually involves parsing log files too, so I've probably got some relevant example code at work :).

If you're not limited to a 2D array, then a hash of arrays indexed to the timestamps would probably work, though the total might have to be stored in a different data structure with that.
 
Last edited:
Back
Top Bottom