in reply to How to parse a logfile to a HTML table format
I assume you know how to use the function split. Type "perldoc -f split" if you don't. Using split, you can get all fields and join the fields you want to produce the strings required.
Now from looking at your logs, it seems like all columns have fixed widths. The first 21 chars go to the first cell in the table. Skip one field, then grab the next 13 chars, skip one and get the rest.
To match these fields, one can use a regular expression to do the job. /^(.{21}) (.{13}) (.*)/ should match 21 chars, followed by a space, followed by 13 chars, followed by a space, then the rest. In list context, the matching operator returns a list of all things between brackets.
# example:
my $str = "Sat Jul 21 22:30 2001 144.02.26.399 www.myserver.com";
my ($date, $stuff, $servers) = $str =~ /^(.{21}) (.{13}) (.*)/;
So, to accomplish your task, just do a simple:
print "<table>";
for(@lines){
print "<tr>";
print "<td>$_</td>" for /^(.{21}) (.{13}) (.*)/;
print "</tr>";
}
print "</table>";
And you should be done.
Hope this helps,,,
Aziz,,,
|
|---|