This is a regex solution, just a simplified one!
Almost all parsing can be looked at as:
- Get records (in this case a line)
- Tokenise records (in this case split on whitespace)
- Examine tokens (in this case the grep that ignores any token without a file delimiter / in it)
- 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:
- 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.
- Filenames that can contain the same random \W tokens at the end of the filepath ie Perl::Module:@ which is possible although unlikely
- Fielnames that contain newlines (we won't get proper records) - unsolvable and also improbable
- 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
|