Ok thanks to everyones recommendation here for Apache::LogParse I have managed to build a quite effective log parsing tool.
Except...
The logfiles all have the request part of the logfile in quotes as one string. So it looks like this normally:
GET /some/path.php?somevalue=eddie HTTP/1.1
but the problem is that it doesn't ALWAYS look like that. But somehow I need to slit that string into the Method, Request (before the ?), URI query (after the ?), and the protocol version. If I just split it based on the string above I of course run into the problem of "Use of uninitialized value in concatenation (.) or string" because of course the variables I split into get set as undefined due to the string not always appearing consistently. Sometimes it's lacking the protocol version, sometimes there isn't a URI query, sometimes the whole string is just one clump of characters due to some goofy attempt against the web server.
So I'm hoping someone can offer advice on how I can do this so that if the string doesn't contain all four components, the variable just gets set to "" or something.
so far I am stuck just doing something like this:
sub split_request( $ )
{
my $http_request = $_[0];
my $method = "";
my $web_request = "";
my $request = "";
my $uri = "";
my $version = "";
($method,$web_request) = split( / /,$http_request, 2 );
($request,$version) = split( / /,$web_request, 2 );
($request,$uri) = split( /\?/,$request );
}
help?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.