cmv has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use POE::Wheel::Followtail and POE::Filter::Line to deliver messages to me from a file with a specific format. I'm trying to build the correct InputRegexp to get this to happen for me, but am having problems understanding why my attempts are not working. None of my attempts work, and the uncommented one gets me closest (but will also match things I don't want it to).
The attached script shows an example of the data format I have, and my stumbling through learning about InputLiteral and InputRegexp to try and get things to work as I'd like. A working script should provide output as follows:
On a side note, I'm wondering about message 6. In this case (assuming the file doesn't grow anymore) message 6 will never be output. Is that correct or is there some way to get it to assume message 6 is a single line and print it out if the file doesn't grow for say, 2 seconds? Also, if that could be done, then what would be a logical way to handle things when the assumption is wrong?Msg(1): Message 1 Line 1 Msg(2): Message 2 Line 1 Message 2 Line 2 Msg(3): Message 3 Line 1 Message 3 Line 2 Message 3 Line 3 Msg(4): Message 4 Line 1 Message 4 Line 2 Message 4 Line 3 Message 4 Line 4 Msg(5): Message 5 Line 1 Message 5 Line 2 Message 5 Line 3 Message 5 Line 4
Thanks
-Craig
Update: Added readmore tags
use strict; use warnings; use POE qw(Wheel::FollowTail Filter::Line); my $tmpfile = "/tmp/data$$"; my $i=1; POE::Session->create( inline_states => { _start => sub { $_[HEAP]{tailor} = POE::Wheel::FollowTail->new( Seek=>0, Filename => "$tmpfile", InputEvent => "got_log_line", Filter => POE::Filter::Line->new( #InputLiteral=>"\n+++", #InputRegexp=>"\n\\+\\+\\+", InputRegexp=>"\n[+*][+*][+*]\\s+", #InputRegexp=>"\n(\\*\\*\\*)|(\\+\\+\\+)\\s+", #InputRegexp=>"\n(\\+\\+\\+)|(\\*\\*\\*)\\s+", ), ); }, got_log_line => sub { print "Msg($i):\n$_[ARG0]\n"; $i++ } } ); open(DATA, ">$tmpfile") || die "Can't open $tmpfile"; print DATA " *** Message 1 Line 1 +++ Message 2 Line 1 Message 2 Line 2 *** Message 3 Line 1 Message 3 Line 2 Message 3 Line 3 +++ Message 4 Line 1 Message 4 Line 2 Message 4 Line 3 Message 4 Line 4 +++ Message 5 Line 1 Message 5 Line 2 Message 5 Line 3 Message 5 Line 4 *** Message 6 Line 1"; close(DATA); POE::Kernel->run(); exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: POE::Filter::Line InputRegexp Help Requested
by bingos (Vicar) on Aug 19, 2010 at 08:46 UTC | |
|
Re: POE::Filter::Line InputRegexp Help Requested
by james2vegas (Chaplain) on Aug 18, 2010 at 22:36 UTC | |
|
Re: POE::Filter::Line InputRegexp Help Requested
by cmv (Chaplain) on Aug 19, 2010 at 14:00 UTC |