in reply to Hi all, need abit of help!
The first thing to do is ask yourself how you would write down instructions for a person to do it:
Next pretend that this person knows absolutely nothing about the business, and is an idiot savant that only knows math well. Also, they don't understand English except for your instructions.
Reading the log file needs to be broken down: how do you identify a record? Which strange symbols are the start/end? (Likely a newline (\n) character, or perhaps a line with the symbols "DRIVE BACKUP START" on it then one with the symbols "DRIVE BACKUP FINISHED" on it.)
Regular expressions help a lot here, but reading a line at a time and skipping the irrelevant ones may be good enough.
Once you've found a bunch of symbols that constitute a record, you need to say how to find the elements of it you care about. How do you know what the "drive" is? (First "Space, a-z then colon" in the record?) Where is the start time, and so on.
Regular expressions usually help even more for this.
Once you've found and picked out the info you want, you need to write it out into the CSV. Writing a CSV like that, you'll want to open a new file and write out the header line before you start looking at records.
Since there shouldn't be any commas in the data, you shouldn't need any fancy stuff for escape characters and quoting rules. So, you want to just copy out all the info symbols in the order you want with commas in between.
Write down all those very simple steps using #comments in your .pl file, and then slowly fill in with perl code after each one.
Compile and run often to make sure you're still on the right track. Once you get to the end, you're done! :)
PS:
You'll want to bookmark http://perldoc.perl.org for looking up all the basics and syntax. (If your browser window isn't exactly 950 pixels wide, try the Stylish addon for firefox with http://userstyles.org/styles/20328 to make the page render with a dynamic width.)
Also, be sure to use strict; use warnings; at the top of your program. It is best to hear about the problems in your code as soon as possible, rather than having things go mysteriously wrong. I also recommend running the program often, after adding each little piece of code. That way when it starts failing to compile, you know right where the bug is. :)
|
|---|