I want to parse a web log file that starts with the following lines: #Software: Microsoft Internet Information Services 6.0 #Version: 1.0 #Date: 2001-12-07 21:36:29 #Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status 2001-12-07 21:36:29 192.168.73.168 GET /scripts/root.exe /c+dir 80 - 192.168.212.230 - 302 2001-12-07 21:36:29 192.168.73.168 GET /MSADC/root.exe /c+dir 80 - 192.168.212.230 - 302
I want to read the #Fields line and read the fields after that into a list. Here is what I have and it's not working: #construct the monthly summary opendir (DIR, "$iislogs") || die "Unable to open $iislogs because:\n$!\n"; @dirs = readdir(DIR); foreach $dir (@dirs) { if ($dir =~/ex(.*)\.log/i) { open (LOGFILE, "$iislogs\\$dir") || die "unable to open $dir because:\n$!\n"; } while ( <LOGFILE> ) { my $record = <LOGFILE>; chomp $record; if ( /Fields/ ) { @fields = split / /, $record; } } } I also want to read future lines and fill in the fields column in a report style format that is more organized than the log file itself. Any help is appreciated. --Paul