in reply to POE::Wheel::FollowTail to read binary records!?!

Folks-

(however using it as a filter on POE::Wheel::FollowTail still doesn't work - more on this later).

I take back this statement - everything seems to be working fine using the attached code. My apologies.

Please feel free to comment on the code, or a better way to do this - it's my first time.

Thanks

-Craig

Update: Fixed buffering bug (removed '|$' in regular expression)

use strict; use warnings; my $data='ThisIsBeginningGarbagefefefefe037e01000001000a666c7832313100 +00000000000000003c0200000049b7e983000001030000015a000000000000000a003 +25b15000114b0fefefefe037e01000001000a666c78323131000000000000000036bc +0200000149b7e983000001030000015b44988c1a0000000a00000028000114b002000 +00249b7e983000001030000015a00000000000000070032343200018c640200000349 +b7e983000001030000015b4475066c000000080000000400018c640200000449b7e98 +3000001030000015a0000000000000003003233da0001877d0200000549b7e9830000 +01030000015b44c0f03f00000006000000020001877d0200fe49b7e98300000210000 +0015c00000000014a00010000000000011475020000ff49b7e983000002200000015a +000000000000000a0032a969000114d60200010049b7e983000002200000015b4427f +d090000000300000005000114d60200010149b7e983000002200000015a0000000000 +0000110032a9010001132a0200010249b7e983000002200000015b4190ca460000000 +00000005c0001132a0200010349b7e983000002200000015a00000000000000110032 +f6ec000112410200010449b7e983000002200000015b411dadd4000000000000005c0 +00112410200010549b7e983000002200000015a00000000000000110032a90200fefe +fefe037e01000001000a666c78323131000000000000000036bc0200000149b7e9830 +00001030000015b44988c1a0000000a00000028000114b00200000249b7e983000001 +030000015a00000000000000070032343200018c640200000349b7e98300000103000 +0015b4475066c000000080000000400018c640200000449b7e983000001030000015a +0000000000000003003233da0001877d0200000549b7e983000001030000015b44c0f +03f00000006000000020001877d0200000649b7e983000001030000015a0000000000 +0000070032340a00018b400200000749b7e983000001030000015b44407da20000000 +8000000040001'; # Create the tmp file to tail later on... $data = pack('H*', $data); my $tmpfile = "tmpdata"; open(TMPDATA, ">$tmpfile") || die "Can't write file $tmpfile"; print TMPDATA $data; close(TMPDATA); use POE; use POE::Wheel::FollowTail; use POE::Filter::Block; # Create custom length encoder/decoder... sub _myencode { print STDERR "_myencode\n" }; sub _mydecode { my $stuff = shift; print STDERR "M1: ", unpack('H72', $$stuff), "...\n"; $$stuff =~ /^(.*?\xfe{4}.*?)(\xfe{4})/s || return; my $length = length($1); return($length); } # Create a POE::Filter::Block with my custom length encoder/decoder... my $filter=POE::Filter::Block-> new(LengthCodec=>[\&_myencode,\&_mydecode]); # Create POE::Wheel::FollowTail session using my customized filter... POE::Session->create( inline_states => { _start => sub { $_[HEAP]{tailor} = POE::Wheel::FollowTail->new( Seek=>0, Filename => $tmpfile, Filter=>$filter, InputEvent=>"got_binary_message", ); }, got_binary_message => sub { print STDERR "M2: ", unpack('H72', $_[ARG0]), "...\n", length($_[ARG0]), " characters\n"; }, } ); POE::Kernel->run(); exit;