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
    Hi sandy105 :) readdir is no fun at all, Path::Tiny on the other hand is fun :)
    use Path::Tiny qw/ path /; my @logfiles = path( shift )->children( qr/\.log$/i );

      I rarely use modules because they are not available on the server where i deploy my scripts.

      Since i run windows at home , I rarely write perl at home for personal purposes .But yeah i installed some modules including Path::Tiny the other day . I plan to explore that and some XML parsing modules as well dabble with OO programming in perl , which i haven't done before.Infact all the lagacy scripts i maintain at my company are huge ~5k lines of code and most scripts are similar to other scripts.