Hey I am a newbie to perl and I can't seem to solve this problem.My perl program executes some command files each of which create a log file in the format "server.YYYY-MM-DD.HH-MM-SS.XXX.log". After executing the command files i wish to parse through the log files created and look for errors.Could you help me regarding how to search for the log files and parse them.

Hey I am a newbie to perl and I can't seem to solve this problem.My perl program executes some command files each of which create a log file in the format "server.YYYY-MM-DD.HH-MM-SS.XXX.log". After executing the command files i wish to parse through the log files created and look for errors.Could you help me regarding how to search for the log files and parse them.

Your question was fairly vague in a sense.. are the log files going to be in their own directory? If so, just grep for .log files, then open them for reading to perform the parsing. If they are scattered, you can change the \.log regex to something to match the kind of timestamp you're after. Unfortunately I have no idea of the log files format, or what you're trying to parse for so I can't be of any more help.
Another method for searching for files could be File::Find - this also searches recursively.

use strict;
use warnings;

opendir(LOGS, '.');
my @files = grep(/\.log$/, readdir(LOGS));
closedir(LOGS);

for (@files) {
    open(LOG, "<$_") or die "Could not open '$_'\n";
    while(<LOG>) {
        chomp(my $line = $_);
        print $line, "\n";
    }
    close LOG;
}

Edited 5 Years Ago by insertable: n/a

This article has been dead for over six months. Start a new discussion instead.