I am working on a script which will tail a log file (using file::tail) and then write data for certain events to a database. It needs to be generic enough that it can be used on multiple log files, which may have different formats and different datapoints to be written. To handle all of this, I am reading in a configuration from a separate file. The configuration will have lines that specify what we are looking for and how we find that data in the specific log files we're looking at.
In the configuration file, you will have something like:
type event datapoints some_type some_grep_string event_start:line[0] || event_end:substr(line[3], 0, index(line[3], ' '))
I am reading the log file line-by-line into a variable $line, then using split to populate an array @line. So for the first datapoint (event_start:line[0]) the variable is event_start, and the value for it is the first value in the @line array.
The second case is where it gets tricky. I need to be able to read in the string 'substr(line[3], 0, index(line[3], ' '))' and recognize that there are perl commands embedded in it. How do I read in a string that say "substr(blah, foo, bar)" and tell perl that it needs to find the value blah and take the substring from foo to bar? Especially when there may be additional commands (such as the index) embedded within it?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |