Hi. I'm a newbie to POE, and I'm about to put it to work on a production
site (fingers crossed). I don't doubt POE, just my rusty Perl. I'm having
one issue, and wondered if any of you have come across something similar.

 

I'm running the script on the poe.perl.org site found here, second script:

 

http://poe.perl.org/?POE_Cookbook/TCP_Servers
<http://poe.perl.org/?POE_Cookbook/TCP_Servers> 

 

I've modified so that instead of echoing, the stream is being written to a
file. The problem I'm having is that I can't seem to recognize the ascii
start/stop characters I'm receiving from my content source. I'd like to
write to different files as these characters are found in the stream.

 

Let me say also that I'm quite rusty with my Perl, so thanks for your
patience. Here's the code that's currently working and writing to a single
file, and below it, the same sub as I've tried to listen for the ascii
start/stop stream characters.

 

sub socket_input{

    my ( $heap, $buf ) = @_[ HEAP, ARG0 ];

    $buf =~ s/>[\s]{2}</>\n</gs;

    open(FH,'>>/usr/local/sportsticker/feed.xml');

    print FH "$buf\n";

    close(FH);

}

 

 

sub socket_input{

    my ( $heap, $buf ) = @_[ HEAP, ARG0 ];

    $buf =~ s/>[\s]{2}</>\n</gs;

    my $synch_char = chr(22);       # synch char

    my $soh_char = chr(1);          # start of header char

    my $eot_char = chr(4);          # end of transmission char

    if($buf =~ /$synch_char{2}$soh_char/) {

        # strip off start chars

        $buf =~ s/$synch_char{2}$soh_char//;

        # start new file

        my $fileName = "/usr/local/sportsticker/feed2.xml";

        open(FH,">>$fileName");

        $counter++;

    }

    if($buf =~ /$eot_char/) {

        # strip off end-of-file char

        $buf =~ s/$eot_char//;

        print FH "$buf\n";

        close(FH);

    }

 

}

 

 

Also, I think the buffer ( $buf ) is screwing up the stream going to the
file. XML tags are occasionally getting truncated to the next line, making
the xml file fail validation. Any ideas about getting around this
limitation?

 

Environment is Linux, receiving XML stream. Thanks for any help or pointers
you can offer.

 

 

------------------------------

Jeff Moser

Senior Web Developer

 <http://www.ihigh.com/> ihigh Inc. / Host Interactive
<http://www.hostinteractive.com/> 

859.232.8282

 

------------------------------ 

 

Reply via email to