Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Net::IRC and File::Tail

by naez (Initiate)
on Aug 16, 2007 at 09:45 UTC ( #632970=note: print w/replies, xml ) Need Help??


in reply to Re: Net::IRC and File::Tail
in thread Net::IRC and File::Tail

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?

Replies are listed 'Best First'.
Re^3: Net::IRC and File::Tail
by Corion (Pope) on Aug 16, 2007 at 09:52 UTC

    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.

      Hm. This might explain the lack of action when I us the "tie" example
      I will try this instead, but I am currently getting an error message when I run that code
      I'll try to work it out though..
      erromsg:
      Can't use an undefined value as filehandle reference at ./unixfh line 4.
      #!/usr/bin/perl -w use strict; my $logfile= "./totte.log"; open my $log, "| -", 'tail', '-f', $logfile or die "Couldn't read logf +ile '$logfile': $!";

        My code is different from your code. My code works. I test it as follows:

        #!/usr/bin/perl -w my $logfile = "./totte.log"; open my $log, '-|', qw(tail -f), $logfile or die "Couldn't tail logfile '$logfile': $!"; while (<$log>) { chomp; print "Got line >>$_<<\n"; };

        Note the order and the lack of whitespace in the second argument to open.

        The whole console session is:

        osabst@dfrsifc1:/tmp $ cat >totte.log test osabst@dfrsifc1:/tmp $ perl -w tmp.pl Got line >>test<<

        This is where I add another line to the logfile from another session

        Got line >>test2<< $ cat tmp.pl #!/usr/bin/perl -w my $logfile = "./totte.log"; open my $log, '-|', qw(tail -f), $logfile or die "Couldn't tail logfile '$logfile': $!"; while (<$log>) { chomp; print "Got line >>$_<<\n"; };

        If you compare the needed framework knowledge and the code size of the two examples, you might understand why I consider POE a "solution". I find the programming model of POE especially inconvenient because the language does little to support something like local scope for event based/message passing systems, unless you consider manually keeping state in a stash as support.

        Still, thanks for pointing out that there is a working solution with POE and also pointing towards http://poe.perl.org which is a valuable resource if you want to use POE.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2020-07-09 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?