in reply to Waiting for multiple filehandles
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Waiting for multiple filehandles (threads)
by insaniac (Friar) on Mar 22, 2005 at 15:34 UTC | |
by Mugatu (Monk) on Mar 22, 2005 at 18:11 UTC | |
by merlyn (Sage) on Mar 22, 2005 at 19:16 UTC | |
| |
by BrowserUk (Patriarch) on Mar 22, 2005 at 18:57 UTC | |
by Tanktalus (Canon) on Mar 22, 2005 at 19:07 UTC | |
by BrowserUk (Patriarch) on Mar 22, 2005 at 19:27 UTC | |
by Mugatu (Monk) on Mar 22, 2005 at 19:10 UTC | |
| |
by BrowserUk (Patriarch) on Mar 22, 2005 at 15:44 UTC | |
by insaniac (Friar) on Mar 22, 2005 at 16:23 UTC | |
by BrowserUk (Patriarch) on Mar 22, 2005 at 16:52 UTC |