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:

typeeventdatapoints
some_typesome_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?


In reply to Converting strings read from a file into perl commands by Nightthrall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.