Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Reading multiple files at the same time

by l2kashe (Deacon)
on Dec 08, 2003 at 23:41 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-19 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found