This is a regex solution, just a simplified one!

Almost all parsing can be looked at as:

  1. Get records (in this case a line)
  2. Tokenise records (in this case split on whitespace)
  3. Examine tokens (in this case the grep that ignores any token without a file delimiter / in it)
  4. Extract data from the tokens (the simple RE in the map)

The only edge cases that will be missed are ones for which there is probably no robust solution. These are:

  1. A filename without a filepath. But this is just a word token and is only identifiable if you know all the possible tokens or you can rely on say file.format syntax.
  2. Filenames that can contain the same random \W tokens at the end of the filepath ie Perl::Module:@ which is possible although unlikely
  3. Fielnames that contain newlines (we won't get proper records) - unsolvable and also improbable
  4. Dates like 2/8/2008 which will look like a filepath. If these occur they are likely to be in the first token which we can ignore because we know this will always be the logdate.

The thing with a multistage parse is that it is transparent. Because each stage only does a little thing debugging is likely to be far easier and less (un)likely to break the downstream parts.

Cheers

tachyon


In reply to Re^4: Okay, I know why is it failing by tachyon-II
in thread This regular expression has me stumped by tsk1979

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.