Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Net::IRC and File::Tail

by naez (Initiate)
on Aug 16, 2007 at 06:43 UTC ( [id://632937]=perlquestion: print w/replies, xml ) Need Help??

naez has asked for the wisdom of the Perl Monks concerning the following question:

Hi all Seeking some wisdom here... I am trying to combine these 2 modules, so that I can have the perlscript do a "tail -f"
on one file and then chat the output to a channel..
I can get 2 separate programs with each module to work, but when I combine them I get an error message.
What I am aiming for is to used the addfh routine to tie in the open File::Tail filehandle and trigger an event in the Net:IRC structure... makes sense?

Anyhow, errormess is :
Not a GLOB reference at /usr/lib/perl5/5.6.1/i386-linux/IO/Select.pm line 61.

and this is part of the code...
#!/usr/bin/perl -w use Net::IRC; use File::Tail; $name="./totte.log" ; $file=File::Tail->new(name=>$name,debug=>$debug,interval=>1,maxinterv +al=>5, adjustafter=>20,errmode=>"return") or die "Could not open $name: $!"; sub on_logentry { my $INPUT = shift; my $line=$file->read; printf "$line"; printf <$INPUT>; } # Setup the connection variables--- my $irc = new Net::IRC; # Add the external stuff $irc->addfh( $file, \&on_logentry, 'r'); # -------------- Start the IRC Connection ---------------- $irc->start;

Replies are listed 'Best First'.
Re: Net::IRC and File::Tail
by cdarke (Prior) on Aug 16, 2007 at 08:09 UTC
    I think you may be making an incorrect assumption that File::Tail returns a file handle. I can't find anything in the documentation which supports that.
    ?I suggest you step through in debug to find which line your error message is coming from, however there is a problem with the first printf in your on_logentry subroutine - use double quotes instead of single (or none at all).
    Using printf is not necessary here, print would do.
      Thnkas for the quick reply.
      it might be as you suggest, so then I would have to use some other means to do a "tail -f" in conjunction with Net::IRC
      , as the only way that Net::IRC can get external data in is through a filehandle...

      Any suggestions? Not that good with the IO parts...
Re: Net::IRC and File::Tail
by moritz (Cardinal) on Aug 16, 2007 at 09:08 UTC
      THanks. now the error has gone away and the addfh processed fine.
      However when I add a textstring to the end of my logfile (which I tail)
      the event is NOT triggered.. which I think it should be
      Any other suggestions?

        I'm not sure that Net::IRC, resp. IO::Select (which is what Net::IRC uses) work well with tie'd filehandles. A possibly working approach could be to actually use the unix tail command and to read from that filehandle:

        open my $log, "-|", 'tail', '-f', $logfile or die "Couldn't read logfile '$logfile': $!";

        That way you get a real OS-file handle on which the mechanisms used by IO::Select might work better.

        Other than that, maybe you want to look into the other Event mechanisms to handle multiple filehandles, or even POE, although I'm not sure if POE is a solution.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found