Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by Corion (Patriarch)
on Aug 16, 2007 at 09:52 UTC ( [id://632972]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^4: Net::IRC and File::Tail
by naez (Initiate) on Aug 16, 2007 at 10:07 UTC
    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"; };
        When I still could not get this to work as you verified
        I did check the perl version on the box im using... 5.6 !
        When I tested the code on a 5.8 version it rocked, so it's upgrade time
        . Thanks all for now, and I'll let you know later how it goes.
Re^4: Net::IRC and File::Tail
by jasonk (Parson) on Aug 16, 2007 at 11:58 UTC

      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://632972]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-18 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found