Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Help using Net::Telnet to use Rainbow

by downer (Monk)
on Oct 04, 2007 at 15:13 UTC ( #642672=perlquestion: print w/replies, xml ) Need Help??

downer has asked for the wisdom of the Perl Monks concerning the following question:

I am using the Server Mode of the Rainbow Text Classifier. The classifier is fully trained, and is listening to a port (1821) on a server in my lab. The interface through telnet looks like this:
Trying 128.*******.12... Connected to rhino.***.edu. Escape character is '^]'.

i can then input whatever text I want, followed by a newline, a '.' and another newline (all input has to end with "\r\n.\r\n" and it sends back the results of the classification to my terminal. I'd like to automate this, but as this is my first time doing any kind of remote computing, I'm clueless. I've tried the following just to see what, if anything the server is sending me, but it only sends back '1'
use Net::Telnet (); $hostname = "rhino.****.edu"; $pop = new Net::Telnet (Telnetmode => 0); $pop->open(Host => $hostname, Port => 1827); $x = "Kingdom Hearts is a series of action role-playing games develope +d and publ ished by Square Enix (formerly Square). It is the resu +lt of a collaboration betw een Square and Disney Interactive Stud +ios, and is under the direction of Tetsuya Nomura"; $x .= "\r\n.\r\n"; $pop->print($x); $f = $pop->waitfor('//'); print "$f\n";

stupid code, to be sure, i'd just like to know the server is sending me something. I can't check even this. I beg the perl monks for wisdom. please advise me!

Replies are listed 'Best First'.
Re: Help using Net::Telnet to use Rainbow
by Sidhekin (Priest) on Oct 04, 2007 at 15:25 UTC

    $f = $pop->waitfor('//'); print "$f\n";

    From the documentation, waitfor just returns success or failure in scalar context. I'd say you probably want to call waitfor in list context:

    ($f) = $pop->waitfor('//'); print "$f\n";

    ... or even:

    ($f, $match) = $pop->waitfor('//'); print "$f$match\n";

    print "Just another Perl ${\(trickster and hacker)},"
    The Sidhekin proves Sidhe did it!

      I found the problem. yes, I need to call waitfor in list context, but instead of "\r\n.\r\n", I tried just "\n.\n" and it works fine.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://642672]
Approved by Sidhekin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2021-02-25 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?