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 <
[email protected]>
Subject: Re: Help: chat2.pl
Message-ID: <
[email protected]>
Originator:
[email protected]
Sender:
[email protected] (USENET News System)
Reply-To:
[email protected] (Tom Christiansen)
Organization: University of Colorado, Boulder
References: <
[email protected]> <
[email protected]> <
[email protected]>
Date: Tue, 30 Nov 1993 21:53:38 GMT
Lines: 73
:-> In comp.lang.perl,
[email protected] (David Rensin) writes:
:In article <
[email protected]>
[email protected] (Steve Davis) writes:
:>David Rensin (
[email protected]) 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 (
[email protected])
:> 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
[email protected]
"Will Hack Perl for Fine Food and Fun"
Boulder Colorado 303-444-3212