This approach has one large pitfall, which you are only guaranteed to sidestep if you control the web server. I mention it here as a caveat to whoever might pick up your code and then wonder why it fails at inopportune times.

The set of fields in an IIS logfile is adjustable via the IIS control panel. When IIS starts a new logfile, it prints the names of the fields that it will log in a #Fields: comment. IIS lets you change this set of fields in mid-log, and then emits a new #Fields: comment into the log in mid-stream. Boom. There goes your script.

Does this ever happen in practice? It has to me. I've seen our network or support folks change the set of fields logged while they're diagnosing connectivity problems. Even if they're aware that it's going to cause analysis problems, that's easy to overlook in the heat of battle, or write off as SOP (Someone Else's Problem).

The code snippet that demonstrates how to cope with this is here, posted by your truly as an early contribution before I registered at the Monastery. In brief, it introduces an level of indirection by way of a hash. It'll probably introduce a small-but-measurable performance hit, which you'll need to weigh against the risk of your script failing at the worst possible moment.


In reply to Re: Efficiency revisited (a caveat) by dws
in thread Efficiency revisited by tekniko

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.