Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to get the logs file name from the webfacts.conf which basicly looks like this:

yuan.sina.com|ACTIVITY_LOG|FILE /home/archive/logs/access_log.yuan-tan +is5 dailynews.sina.com|ACTIVITY_LOG|FILE /home/archive/logs/access_log.dai +lynews-tanis5 i*|ACTIVITY_LOG|FORMAT COMBINED *|ACTIVITY_LOG|DIGI_SIGN YES *|ACTIVITY_LOG|TRANSFER_DIRECTORY /home/ftp/pub/webfacts *|ACTIVITY_LOG|MIDNIGHT_ROLL NO *|ACTIVITY_LOG|SIZE_LIMITS NO # *|ERROR_LOG|FILE /home/archive/logs/error_log.webfacts

right now it is been hard coded on my script as like this

@hosts = ('yuan-tanis5', 'dailynews-tanis5');

Can someone tell me how to get those information from the file? so I don't have to hard code it???

thanks

2001-03-03 Edit by Corion : Added <CODE> tags

Replies are listed 'Best First'.
Re: get log file files
by chromatic (Archbishop) on Feb 17, 2001 at 02:36 UTC
    My tool of preference here is split. You could do something like this:
    my @hosts; while (<INPUT>) { # log file lines have multi-character domain names at the start if (/^\w+/) { my $file = (split(/\|/, $_, 3))[2]; if ($file =~ s!/access_log\.(.+)$/) { push @hosts, $1; } } }
    Other approaches are equally valid. (Hey, davorg's book is full of nice tricks like this.)
Re: get log file files
by a (Friar) on Feb 17, 2001 at 10:56 UTC
    Yes, something like:
    while (<WEB_FILE>) { chomp; my ($host, $log, $file) = split(/\|/); if ( $log eq 'ACTIVITY_LOG' and $file =~ s/^FILE //) { $host_access_files{$host} = $file; } # should put $host's activity log file name into # $host_access_files{$host} } # while WEB_FILE

    a