Article 8523 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:8523
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.ecn.bgu.edu!usenet.ins.cwru.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!boulder!wraeththu.cs.colorado.edu!tchrist
From: Tom Christiansen <tchrist@cs.Colorado.EDU>
Subject: Re: Help: chat2.pl
Message-ID: <CHBrHE.322@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: <2dg54i$8iq@mojo.eng.umd.edu> <2dgbcpINN4n9@tonto.ksu.ksu.edu> <2dgdlm$cp5@mojo.eng.umd.edu>
Date: Tue, 30 Nov 1993 21:53:38 GMT
Lines: 73

:-> In comp.lang.perl, rensin@eng.umd.edu (David Rensin) writes:
:In article <2dgbcpINN4n9@tonto.ksu.ksu.edu> strat@tonto.ksu.ksu.edu (Steve Davis) writes:
:>David Rensin (rensin@eng.umd.edu) writes:
:>
:>:Does anyone know why $output is being set to NULL in the following line of
:>:code ?
:>
:>:&chat'expect($handle,30,'(.*)','$output=$1;print $output."\n"');
:>
:>You want to use $& instead of $1.
:>-- 
:>                                               Steve Davis (strat@cis.ksu.edu)
:>                                                       Kansas State University
:>
:>"I'll say it again for the logic impaired."  -- Larry Wall

Here's an example of a little chat2 client I wrote for my perl
networking class, which, I believe, is some of the only docs 
on chat2 extant today. :-( 

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 Christiansen      tchrist@cs.colorado.edu       
      "Will Hack Perl for Fine Food and Fun"
	Boulder Colorado  303-444-3212


