Article 8422 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:8422
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.utdallas.edu!convex!convex!darwin.sura.net!howland.reston.ans.net!sol.ctr.columbia.edu!news.kei.com!das.wang.com!wang!news
From: dov@menora.weizmann.ac.il (Dov Grobgeld)
Subject: An additional open routine for chat2.pl
Organization: Mail to News Gateway at Wang Labs
Date: Sun, 28 Nov 1993 23:12:21 GMT
Message-ID: <9311282112.AA20425@menora.weizmann.ac.il>
Sender: news@wang.com
Lines: 54

Here is a suggestion for an additional open routine for the chat2.pl
library. It duplicates a user file handle to make it conform to the chat
format. This makes it possible to use chat2 together with programs that
duplicates stdin and stdout for their own input, e.g. the ~C option of 
tip, as well as other filehandles already open, e.g. to a modem.

    ## $handle = &chat'open_duphandle(handle);
    ## duplicates an input file handle to conform to chat format
    
    sub open_duphandle { ## public
    	*S = ++$next;
    	open(S,"<&$_[0]");
    	$next; # return symbol for switcharound
    }
    
Here is an example which uses this routine.

    # The following lines makes stdin unbuffered
    
    $BSD = -f '/vmunix';
    
    if ($BSD) {
        system "stty cbreak </dev/tty >/dev/tty 2>&1";
    }
    else {
        system "stty", '-icanon';
        system "stty", 'eol', '^A';
    }

    require 'mychat2.pl';
    
    &chat'open_duphandle(STDIN);
    
    print 
    &chat'expect(3,
      '[A-Z]', '" :-)"',
      '.', '" :-("',
      TIMEOUT,  '"-o-"',
      EOF, '"\$\$"'),
    "\n";

Finally, thanks Randalf for writing chat2.pl. It is a terrific piece of
code. :-)

Regards,
    Dov
    
-- 
                                                        ___   ___
                                                      /  o  \   o \
Dov Grobgeld                                         ( o  o  ) o   |
The Weizmann Institute of Science, Israel             \  o  /o  o /
"Where the tree of wisdom carries oranges"              | |   | |
                                                       _| |_ _| |_


