CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Need to add check

 



Podarok
New User

Jun 1, 2014, 10:08 AM

Post #1 of 9 (5229 views)
Need to add check Can't Post

Hello i got a code which analyzes log files from one folder, I need to add a check in this for cycle to check if the log file's name is "vtc.log", it will skip the log file. Please help!

Code
# ------------------------------------------------------------------------------ 
# process log sources ... the endless while loop is a placeholder.
my $more_logs = !$opt->get('nologs');
while ($more_logs) { # infinite loop
my $logsource = load_logsources();
if (!defined $logsource or @$logsource == 0) {
$ERR->fatal("No log sources defined! You must configure a log source (or use -log on command line)!");
}

my @total;
my $game = new PS::Game($conf, $db);
foreach my $source (@$logsource) {
my $feeder = new PS::Feeder($source, $game, $conf, $db);
next unless $feeder;

# Let Feeder initialize (read directories, establish remote connections, etc).
my $type = $feeder->init; # 1=wait; 0=error; -1=nowait;
next unless $type; # ERROR

$conf->setinfo('stats.lastupdate', time) unless $conf->get_info('stats.lastupdate');
@total = $game->process_feed($feeder);
$total_logs += $total[0];
$total_lines += $total[1];
$conf->setinfo('stats.lastupdate', time);
$feeder->done;

last if $GRACEFUL_EXIT > 0;
}
&main::exit if $GRACEFUL_EXIT > 0;

last;
}



Laurent_R
Veteran / Moderator

Jun 1, 2014, 10:58 AM

Post #2 of 9 (5209 views)
Re: [Podarok] Need to add check [In reply to] Can't Post

Hi,

I have some trouble understanding your code and what it's doing since it seems to be using modules unknown to me, but assuming that $source contains the name of the log files, it seems to me that you could just add one line at the top of your foreach loop:


Code
	foreach my $source (@$logsource) {  
next if $source eq "vtc.log";
my $feeder = new PS::Feeder($source, $game, $conf, $db);
# ...



Podarok
New User

Jun 1, 2014, 1:35 PM

Post #3 of 9 (5188 views)
Re: [Laurent_R] Need to add check [In reply to] Can't Post

Thank you, but it didn't help me, the log vtc.log is still processing and is not skipping :(


Zhris
Enthusiast

Jun 1, 2014, 9:48 PM

Post #4 of 9 (5014 views)
Re: [Podarok] Need to add check [In reply to] Can't Post

What is the output if you print each source, its possibly a full path to the log as oppose to a filename, in which case Laurent's condition will need adjustment. Its difficult to fully understand what your code is doing and source might not be the right variable at all.


Code
	foreach my $source (@$logsource) {  
print "$source\n";
my $feeder = new PS::Feeder($source, $game, $conf, $db);
# ...


Chris


(This post was edited by Zhris on Jun 1, 2014, 9:56 PM)


FishMonger
Veteran / Moderator

Jun 2, 2014, 7:28 AM

Post #5 of 9 (4880 views)
Re: [Podarok] Need to add check [In reply to] Can't Post

This will help find the answer.

http://www.perlmonks.org/?node_id=174051


Podarok
New User

Jun 2, 2014, 9:17 AM

Post #6 of 9 (4835 views)
Re: [Laurent_R] Need to add check [In reply to] Can't Post

I found the correct part of the code which contains the name of the log file ($src is the variable which actually is the full path to log file).
Your code doesn't work here :/ Could you please help me?
I need something like :

if($src == "C:\...\vtc.log") {
skip this file and go to the next one!
}

Thanks in advance


Code
	while (defined(my $ev = $feeder->next_event)) { 
my ($src, $event, $line, $game) = @$ev;
$game ||= $self;
if ($src ne $lastsrc) {
$lastsrc = $src;
$game->new_source($src);
}

$game->event($src, $event, $line);

if (time - $stream_time >= $stream_save_seconds) {
# save all stats in-memory (if the feeder supports it)
# this is only used from stream feeders since a stream
# can have multiple games stored within it, in memory.
$feeder->save_games;
$stream_time = time;
}

# every X lines we should recalc everything to help with really long processing passes
$count++;
if (($max_lines and ($count % $max_lines == 0)) or (time - $start >= $max_seconds)) {
$count = 0;
$start = time;

# perform all daily updates (except awards)
foreach my $d (@PS::Game::DAILY) {
next if $d eq 'awards'; # we don't do awards (they take too long)
#next if $per_day_ranks and $d eq 'ranks'; # don't do ranks if per_day_ranks is enabled
my $f = 'daily_' . $d;
$game->$f if $game->can($f);
}
}

# If the day changes re-calculate player ranks, only if configured
if ($per_day_ranks and defined $game->{last_day} and
$game->{last_day} != $game->{day} and
$game->{last_ranked} != $game->{day} and
$feeder->total_lines - $game->{last_ranked_line} >= 1000) {
$game->daily_ranks;
$game->{last_ranked} = $game->{day};
$game->{last_ranked_line} = $feeder->total_lines;
}
}



FishMonger
Veteran / Moderator

Jun 2, 2014, 9:36 AM

Post #7 of 9 (4826 views)
Re: [Podarok] Need to add check [In reply to] Can't Post

Add this near the top with your other modules.

Code
use File::Basename;


Then add this to your while loop.

Code
next if basename($src) eq 'vct.log';



(This post was edited by FishMonger on Jun 2, 2014, 9:36 AM)


Podarok
New User

Jun 2, 2014, 9:57 AM

Post #8 of 9 (4816 views)
Re: [FishMonger] Need to add check [In reply to] Can't Post

did this, still processing "vtc.log" :(


FishMonger
Veteran / Moderator

Jun 2, 2014, 10:10 AM

Post #9 of 9 (4810 views)
Re: [Podarok] Need to add check [In reply to] Can't Post

If you put that "next" statement in the proper place, then it should have skipped over the processing of that file. If it didn't then the value of $src is not what you expect.

You should use the Data::Dumper module to output that var to see what it holds and post that output so we can see how to proceed.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives