Article 6187 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:6187
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!spssig.spss.com!news.oc.com!news.kei.com!yeshua.marcam.com!usc!cs.utexas.edu!uunet!boulder!wraeththu.cs.colorado.edu!tchrist
From: Tom Christiansen <tchrist@cs.Colorado.EDU>
Subject: Re: Usage of open2-pkg or chat2-pkg
Message-ID: <CE1n21.E8r@Colorado.EDU>
Originator: tchrist@wraeththu.cs.colorado.edu
Sender: news@Colorado.EDU (USENET News System)
Reply-To: tchrist@cs.colorado.edu (Tom Christiansen)
Organization: University of Colorado, Boulder
References: <7491344358-322371@d24.wu-wien.ac.at>
Date: Tue, 28 Sep 1993 03:01:13 GMT
Lines: 76

From the keyboard of schoenf@d24.wu-wien.ac.at (Werner Schoenfeldinger):
:Dear Programmers,
:
:I need to build a telnet-like Interface which connects to a port on a given
:host and establishes a 2-way connection. The CLIENT-Example program 
:of the Camel-Book would normally fulfill these requirements BUT,....
:it reads only lines with a Carrige Return.
:
:So if you have lines like: 
:
:'Please enter your Username:'
:
:without a carrige -return, you can get them only after the next input.
:
:So I intended to program this myself using the chat2 or open2-package. My
:difficulties are that there is no documentation, nor examples with the packages,
:so I do not really understand how to use them.
:
:I'd be happy for receiving some examples or for an advice how to overcome this
:problem in an elegant way.

It's not too elegant, but if you don't use telnet directly (randal
posted one of those lately), you can do this:

    require 'chat2.pl';
    sub waitfor {
	&chat'expect(30, "@_") || die "expected @_";
    } 
    &chat'open_proc("telnet localhost")
	|| die "can't open proc: $!";
    &waitfor("login:");
    &chat'print("sync\n");
    &waitfor("sync");
    do {
	&chat'expect(30,

	    '^Last Login: (.*)\r?\n', q{
		print "It's been awhile since $1\n";
	    }, 

	    'Connection closed by foreign host', q{
		print "conn closed\n";
		$done = 10;
	    },

	    '(.+)\r?\n', q{
		print $&;
	    }, 

	    '^\r?\n$', q{
		print "blank line\n";
		$done++;
	    }, 

	    TIMEOUT, q{ 
		print "Oops, timeout, done at $done\n";
		$done += 2;
	    }, 

	    EOF,     q{ 
		print "EOF!\n";
		$done =  10;
	    }, 
	)
    } until $done > 9;

    &chat'close || die "can't close: $!";

    print "all done $done\n";


--tom
-- 
    Tom Christiansen      tchrist@cs.colorado.edu       
	Perl Consultant Extraordinaire
	Boulder Colorado  303-444-3212


