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++; }

In reply to Re: Opening multiple log files by sandy105
in thread Opening multiple log files by hahazeeq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.