in reply to Opening multiple log files
you could read all the .log files like this below code
opendir(hand,$ARGV[0]); #replace ARGV[0] with your DIR @files = readdir(hand); closedir(hand); foreach(@files){ if(/\.log$/i) { + #if the filename has .log at the end push(@logfiles,$_); } }
you could then take the logfiles array and do a multithreaded processing like below
while (scalar @Threads < scalar @logfiles) { @running = threads->list(threads::running); if (scalar @running < $n_process) { + #spawn threads if no of running threads less that MAX proces +ses defined $filename = $logfiles[$fileindex]; my $thread = threads->new( sub { sorterwriter($filename) } +); #spawning worker threads passing filename to su +broutine push (@Threads, $thread); + #pushing no of threads spawned for checking in outer loop my $tid = $thread->tid; print " - starting thread $tid\n"; $fileindex++; } }
or you could do regular processing by
$nooffiles = @logfiles; $fileindex=0; while ($fileindex <$nooffiles ) { open hanr ,">", "$logfiles[$fileindex]" or die "could not open logfile + .. $!"; $fileindex++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Opening multiple log files
by Anonymous Monk on Jun 15, 2015 at 08:48 UTC | |
by sandy105 (Scribe) on Jun 15, 2015 at 09:07 UTC |