Here's how I do it using threads:
#! perl -slw use strict; use threads; use threads::shared; use Thread::Queue; my $Qin = new Thread::Queue; my $done :shared = 0; async{ open my $fh1, '<', "firewall.log" or die "FWLog : $!"; ( local $_ = <$fh1> and $Qin->enqueue( "F1:$_") ) or Win32::Sleep 10 until $done; close $fh1; }; async{ open my $fh2, '<', "modem.log" or die "Modemlog : $!"; ( local $_ = <$fh2> and $Qin->enqueue( "F2:$_" ) ) or Win32::Sleep 10 until $done; close $fh2; }; while( my $input = $Qin->dequeue() ) { chomp $input; my( $src, $txt ) = split ':', $input, 2; if( $src eq 'F1' ) { print "Firewall: '$txt'"; } else { print "Modem : '$txt'"; } }
This monitors 2 files, and processes all the data in a single place. It is easy to extend to any number of files and you can process the data within the threads rather than centrally if that fits your needs.
In reply to Re: Waiting for multiple filehandles (threads)
by BrowserUk
in thread Waiting for multiple filehandles
by cog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |