CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
open a file with "tail"


New User

Jun 3, 2011, 3:50 AM

Post #1 of 4 (1314 views)
open a file with "tail" Can't Post


I need some help on this, please.
I'm trying to write my script to open a chat log file, parse a string and send a message to the user every time he log in chat (jabber, don't know if it has importance). It works only a little after I run it. It parses fine few rows and after that is hanging on something and do nothing anymore...
I don't see what is wrong with it... Can you take a look and give me a hint please?

Here is:
use strict;
use warnings;

open(LOGFILE,"tail -f chat.log |") || die ("Failed!\n");
if (<LOGFILE> =~ m/user_available for /)
my $string = "$'";
$string =~ /^(.*?)\s/;
my @value = split(/"/, $1);
my $cmd = "echo `/path/to/command/` | sendxmpp -i @value\ -t --message-type=headline -v";
system "$cmd";

Thank you,


Jun 3, 2011, 7:06 AM

Post #2 of 4 (1297 views)
Re: [admoga82] open a file with "tail" [In reply to] Can't Post

Maybe it gets out of sync? You only compare every 2nd line (i.e. only the even-numbered lines) in chat.log (the odd-numbered lines are used inside the while loop, the even-numbered lines are used in the 'if'). I don't know whether you do this on purpose - maybe chat.log has this format.

Also, I don't think it makes sense to use while() on a file followed with tail -f, Since the input doesn't come to an end (unless someone is killing explicitly your tail process).


Jun 3, 2011, 7:07 AM

Post #3 of 4 (1297 views)
Re: [admoga82] open a file with "tail" [In reply to] Can't Post

BTW, see File::Tail on CPAN.

New User

Jun 6, 2011, 12:22 AM

Post #4 of 4 (1274 views)
Re: [rovf] open a file with "tail" [In reply to] Can't Post

Thanks a lot and sorry for my mistake, I'm new to perl. I used File::Tail and the script isn't hanging anymore.



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives