[comp.lang.perl] What am I missing from chat2.pl?

frechett@spot.Colorado.EDU (-=Runaway Daemon=-) (05/27/91)

I have the begginnings of of a script here.. It is based directly off 
of a perl script that is supposed to go off and get the weather so I 
know the syntax is correct.. or should be if the weather sript actually works..
(it can't connect to the machine and times out there) but working with it 
as an example I started this. 
#!/usr/bin/perl

push(@INC,'/users/en-ecen/frechett/perl');
require './chat2.pl';

&chat'open_port('spot.colorado.edu', 4242) || die "open: $!";

&talk("$1\n");
$_ = &listen(1);
&talk("nick Dae\n");

And what does it do....
Undefined subroutine "main'talk" called at /users/en-ecen/frechett/perl/chat line 8.

I just picked up the chat2.pl file and a few examples and a bunch of them 
use talk and listen and my scripts can't find either one.  The examples I 
am looking at have only one require line.. and that is 
require 'chat2.pl';   and mine is correctly placed.. 
> ls ~/perl/chat2.pl
/users/en-ecen/frechett/perl/chat2.pl*

all my other requires work for this directory..  but this doesn't.. ALSO, 
I don't even see one instance of talk in chat2.pl, so what am I missing?

	ian

perl 3 p41

merlyn@iWarp.intel.com (Randal L. Schwartz) (05/27/91)

In article <1991May27.120442.16645@colorado.edu>, frechett@spot (-=Runaway Daemon=-) writes:
| I have the begginnings of of a script here.. It is based directly off 
| of a perl script that is supposed to go off and get the weather so I 
| know the syntax is correct.. or should be if the weather sript actually works..
| (it can't connect to the machine and times out there) but working with it 
| as an example I started this. 

Gosh.  Bug reports against chat2.pl already! :-)

| #!/usr/bin/perl
| 
| push(@INC,'/users/en-ecen/frechett/perl');
| require './chat2.pl';
| 
| &chat'open_port('spot.colorado.edu', 4242) || die "open: $!";
| 
| &talk("$1\n");
| $_ = &listen(1);
| &talk("nick Dae\n");
| 
| And what does it do....
| Undefined subroutine "main'talk" called at /users/en-ecen/frechett/perl/chat line 8.

&talk() was defined near the end of the weather script.  For that
program, I wrote up a &talk() and &listen() that sat on top of
&chat'print() and &chat'expect() so I could watch the dialog in debug
mode.

You can either steal the &talk() and &listen() from the weather
script, or just call &chat'print() and &chat'expect() yourself.

Eventually (like in the *beta* of chat2 :-), I'll roll a canonical
talk and listen into the chat2 package, because I notice myself using
them frequently in my test programs.

Remember... chat2 is still alpha.  If it's missing something, yell at
me.  If you don't understand something about it, yell at me.  If you
like it, just say kind words. :-)

(I'm working on "select" right now, by the way.  Ugh. :-)

qx(echo Just another Perl hacker, >/dev/tty)
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/

frechett@spot.Colorado.EDU (-=Runaway Daemon=-) (05/28/91)

In article <1991May27.160539.8127@iWarp.intel.com> merlyn@iWarp.intel.com (Randal L. Schwartz) writes:
>(I'm working on "select" right now, by the way.  Ugh. :-)
Uh oh.. this doesn't sound good.. as I picked up chat2 hoping to be able to 
do what I was trying to do with select.. 
Here's the situation.. I have a client (addapted from the in the man pages)
and I want to be able to poll stdin and the socket both.. Was hoping to 
find something in chat2.pl but if you haven't written a select then I 
suspect that I am am going to have a bit of aproblem..   

It is a simple matter to listen to the socket and parse what I see and 
such.. OR to listen to the users's input but as soon as I start to try to 
deal with both.. it stalls on something.. Here is a code fragment...

S is the socket.. 

sub fhbits {
	local(@fhlist) = split(' ',$_[0]);
	local($bits);
	for (@fhlist) {
		vec($bits,fileno($_),1)=1;
	}
	$bits;
    }
$rin = "";
$rin = &fhbits('stdin S');
# the problem here is that I don't see ANYTHING in $rin  Is it 
# unprintable.. and just what the hell is it anyway.. 
               if ($child = fork) {
                     for (;;) {
# it pauses here fine.. waiting for something to come through.. 
($nfound) = select($rout=$rin, undef,undef,undef);
# but I am totally stuck here... I couldn't see what $rin was and I can't 
# see what $rout is.. so I don't know what filedescriptors are ready.. 
# not only that but when I put in a line like... 
if ($nfound == 1) { read(S,$output,1024); print "$output"; } 
# and then sent it only stuff through the socket.. it still wasn't 
# trapping it.. It just froze stdin of course.. It just displays what is 
# coming throught the socket but the select didn't see it and read didn't see
# it..   What's wrong?
			if ($output =~ /^\/die|^\/quit/) { do dokill(); exit(0);}
[...]
                    }
                    sleep 3;
                    do dokill();
               }
# now on the other hand.. if I just poll the Socket and ignore stdin
# it reads the socket fine.. 
               else {
                    while (<S>) {
			if (/Temperature/ ) { print "Damn damn damn\n$_"; }
# we have a machine with a temperapture reading on some port.. 
                         print;
                    }
               }
exit(0);


I am confused.. and from what I can tell.. select(2) is not easy to 
deal with at all... Everyone I talk to either says.. 
"I don't know what to tell you"  or the classic
"Well it's been a long time and I did it in C but this should work.... "
And it never does.. 

Any help would be appreciated.. 

	ian

-=Runaway Daemon=-

lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) (06/11/91)

In article <1991May27.215623.20884@colorado.edu> frechett@spot.Colorado.EDU (-=Runaway Daemon=-) writes:
: Here's the situation.. I have a client (addapted from the in the man pages)
: and I want to be able to poll stdin and the socket both.. Was hoping to 
: find something in chat2.pl but if you haven't written a select then I 
: suspect that I am am going to have a bit of aproblem..   
: 
: It is a simple matter to listen to the socket and parse what I see and 
: such.. OR to listen to the users's input but as soon as I start to try to 
: deal with both.. it stalls on something.. Here is a code fragment...
: 
: S is the socket.. 
: 
: sub fhbits {
: 	local(@fhlist) = split(' ',$_[0]);
: 	local($bits);
: 	for (@fhlist) {
: 		vec($bits,fileno($_),1)=1;
: 	}
: 	$bits;
:     }
: $rin = "";
: $rin = &fhbits('stdin S');
: # the problem here is that I don't see ANYTHING in $rin  Is it 
: # unprintable.. and just what the hell is it anyway.. 

It's a bit vector, 8 bits to the byte, so of course it's not guaranteed
to be printable.  You get the bits out with vec() just like you put them in.
Alternately, use unpack('b*', ...) to turn it into a string of 0's and 1's.

:                if ($child = fork) {
:                      for (;;) {
: # it pauses here fine.. waiting for something to come through.. 
: ($nfound) = select($rout=$rin, undef,undef,undef);
: # but I am totally stuck here... I couldn't see what $rin was and I can't 
: # see what $rout is.. so I don't know what filedescriptors are ready.. 
: # not only that but when I put in a line like... 
: if ($nfound == 1) { read(S,$output,1024); print "$output"; } 
: # and then sent it only stuff through the socket.. it still wasn't 
: # trapping it.. It just froze stdin of course.. It just displays what is 
: # coming throught the socket but the select didn't see it and read didn't see
: # it..   What's wrong?

read() calls C's fread() function, which is going to try to read 1024 bytes
come hell or high water (or both, if too many snowballs melt there).  Use
sysread() instead--that's one of the reasons it's there.

Larry