Monks-

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:

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
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?

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;

In reply to POE::Filter::Line InputRegexp Help Requested by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.