good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: How to parse a logfile to a HTML table formatby HyperZonk (Friar) |
on Jul 22, 2001 at 02:28 UTC ( [id://98708]=note: print w/replies, xml ) | Need Help?? |
Update: I note that some people are recommending
substr solutions. If your log is like mine, it isn't actually
fixed width fields (though it may appear to be at first, if
all of the IP addresses have the same width). There is, of
course, a way to work with that (using index), but that
probably is less efficient. Personally, my favorite answer
from below is the split answer, which is probably
better than my regex solution. I'm going to be very general in my answer, to hopefully increase the usefulness of the answer (and salve my conscience about being a homework-troll). Say you've got line-length records of the form: Say you want x, y, and z in one field, and the rest of the stuff in separate fields. You can populate an array (@infile) with the lines from the log file, then do the following: This will create a list of lists that you can output as you need. @output is a list of references to anonymous lists populated with your desire output fields. \s parses whitespace characters, \S parses non-whitespace character. You simply arrange your parentheses to capture however many of the space delimited items you need per field. Note: this code could be optimized for shortness, but I have tried to keep what is happening relatively obvious by explicitly doing things in several steps.
In Section
Seekers of Perl Wisdom
|
|