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

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;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://313308]
and monks are getting baked in the sun...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2017-03-28 01:45 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (326 votes). Check out past polls.