Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Reading multiple files at the same time

by l2kashe (Deacon)
on Dec 08, 2003 at 23:41 UTC ( #313308=note: print w/ replies, xml ) Need Help??


in reply to Reading multiple files at the same time

Or the FileHandle module even
Update: changed vars to more descriptive names

#!/usr/bin/perl use strict; use FileHandle; # what to watch my %monitor = ( 'messages' => '/var/adm/messages', ); # how to watch it. my %handles; for ( keys %monitor ) { $handles{ monitor{$_} } = new FileHandle "$monitor{$_}", "r" or die "Cant open $monitor{$_}: $!\n"; } # And use it # WARNING blocking code ahead!! my $sentinel; # how we get out of the while 1 while (1) { last if $sentinel; while ( my($file, $fh) = each %handles ) { chomp(my $line = <$fh>); print "Saw in file: $file\n$line\n\n"; $sentinel++ if $line =~ m/somethingorother/; } }

Also File::Tail might be of some use along the same lines

use perl;


Comment on Re: Reading multiple files at the same time
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://313308]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-08-31 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls