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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



admoga82
New User

Jun 3, 2011, 3:50 AM

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

Hi,

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:
#!/usr/bin/perl
use strict;
use warnings;

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

Thank you,


rovf
Veteran

Jun 3, 2011, 7:06 AM

Post #2 of 4 (773 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).


rovf
Veteran

Jun 3, 2011, 7:07 AM

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

BTW, see File::Tail on CPAN.


admoga82
New User

Jun 6, 2011, 12:22 AM

Post #4 of 4 (750 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.

Regards,
Adriana

 
 


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

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