STORY
The 35-Year Story of chat.pl and chat2.pl
The 35-Year Story of chat.pl and chat2.pl
- On June 16, 1991 (
91/06/16), I posted a 350-line Perl 4 library calledchat2.pl(V2.01.alpha.7) to thecomp.lang.perlUsenet newsgroup. That single Usenet post went on an extraordinary 35-year journey: silently bundled by Larry Wall as the only code I ever wrote that shipped in the core Perl distribution, containing a tongue-in-cheek hardwired socket constant comment that was invalidated 60 days later by Linus Torvalds announcing Linux, powering the underlying transport engine that bootstrapped CPAN, being deleted from Perl core in 2000 at my own request ("Delete chat2 as requested by Randal"), becoming a Polish.pldomain conference lightning talk punchline (http://chat2.pl), and coming full circle in 2026 in my work governing AI "chat" coding agents. 1. Origin: Scratching an
expectItch in Pure Perl 4 (June 1991)- In 1988, John Ousterhout created Tcl/Tk, and in 1990, Don Libes built
expecton top of Tcl so Unix scripts could interact with conversational command-line programs (passwd,telnet,ftp,fsck) over pseudo-terminals (PTYs) and sockets. Without Ousterhout, we would not have hadtcl/tkorexpect—both essential early Unix tools. - I wanted an
expect-like pattern-matching state machine directly inside Perl 4 that worked cleanly across both TCP sockets and pseudo-terminals (PTYs) without requiring users to install Tcl andexpect. Rather than naming itexpect.pl—both because I did not want to imply a 1-to-1 API mapping to Libes'sexpectand because there was already anexpect.plfloating around—I named my librarychat.pland evolved it intochat2.pl(## chat.pl: chat with a server / ## V2.01.alpha.7 91/06/16 / ## Randal L. Schwartz), posting it tocomp.lang.perlbecause it was solving real automation problems for me. Technical Highlights of
chat2.pl(91/06/16)- Guarded Pattern-Action State Machines with Explicit
'TIMEOUT'and'EOF'Branches:chat'expecttook a timeout and pairs of regex patterns and action bodies, plus dedicated'TIMEOUT'and'EOF'failure guards if a subprocess hung or exited unexpectedly. - Dynamic On-the-Fly Subroutine JIT Compilation & Memoization: Rather than re-interpreting pattern lists on every
select()wake-up,chat'expectdynamically generated a custom Perl subroutine (expectloop000000,expectloop000001, ...) viaeval $casesand memoized it by caller and argument list ($expectsubname{$caller,@}). - Dynamic Typeglob Handle Generation (
chatsymbol000000): Because Perl 4 did not yet have lexical filehandles or object references,chat2.plused magic string auto-increment on$next = "chatsymbol000000"and assigned*S = ++$nextto return unique symbol-table handles for each open TCP socket or PTY subprocess.
- Guarded Pattern-Action State Machines with Explicit
- In 1988, John Ousterhout created Tcl/Tk, and in 1990, Don Libes built
2. The
h2phTrade-Off and the 1991 "Linux" Prophecy- In Perl 4 (prior to Perl 5's compiled XS
use Socket;module), accessing C header constants likeAFINET,SOCKSTREAM, andTIOCNOTTYfrom/usr/include/sys/socket.handsys/ioctl.hrequired loading.phPerl header files (require 'sys/socket.ph'). Those.phfiles only existed if the local system administrator had manually run theh2phtool asrootafter installing Perl—and on a huge fraction of 1991 Unix systems, sysadmins either skipped runningh2phor watchedh2phchoke on complex vendor C preprocessor macros. - To make
chat2.plwork with zero installation dependencies straight off Usenet, I deliberately hardwired the standard BSD socket andioctlconstants(2, 1, 6)(AFINET = 2,SOCKSTREAM = 1,IPPROTO_TCP = 6) and0x20007471(TIOCNOTTY), leaving a tongue-in-cheek comment on lines 32–34:# XXX hardwired $AFSOCKET, $SOCKSTREAM, 'tcp'# but who the heck would change these anyway? (:-) - Sixty days later (August 25, 1991), Linus Torvalds announced Linux on
comp.os.minix—"a different sort of Unix from a new origin." Between Linux (TIOCNOTTY = 0x5422) and System V Release 4 / Solaris (SOCK_STREAM = 2instead of1), those "unchangeable" constants changed right out from underchat2.pl!
- In Perl 4 (prior to Perl 5's compiled XS
3. Silent Inclusion by Larry Wall & Bootstrapping CPAN
- Without my knowledge, [Person/Larry Wall]] scooped my
V2.01.alpha.7posting off Usenet and bundled it directly into the Perl 4 standard library (lib/chat2.pl) on November 5, 1991 (perl 4.0 patch 12, commit [11aea36008). When the release came out and I saw myalpha.7Usenet script published inside the official Perl core distribution, I was completely shocked! - Ironically,
chat2.plbecame the only piece of Perl code I ever wrote that shipped inside the core Perl distribution—freezing myV2.01.alpha.7header,# but who the heck would change these anyway? (:-), and# Recursive invocations are not thought through, and may work only accidentally. :-)onto every Unix machine in the world. - Because
chat2.plwas now guaranteed to be present in/usr/local/lib/perl/chat2.plon every Perl installation worldwide:- Lee McLoughlin at Imperial College London built
ftp.pland themirrorpackage on top ofchat2.pl. - Jarkko Hietaniemi, Andreas König, and the early Perl community used
mirror(ftp.pl->chat2.pl) to synchronize and bootstrap the global CPAN mirror network starting in 1995. - Thus, a 350-line
alpha.7script posted to Usenet became the underlying transport engine that bootstrapped CPAN—the ancestor of every modern language package registry (npm,PyPI,RubyGems,Cargo,pub.dev).
- Lee McLoughlin at Imperial College London built
- Without my knowledge, [Person/Larry Wall]] scooped my
4. Nine Years in Core &
"Delete chat2 as requested by Randal"(1991–2000)- The
Perl/perl5git commit history forlib/chat2.plrecords its entire nine-year lifecycle in core:11aea36008(November 5, 1991 — Larry Wall): ImportedV2.01.alpha.7intoperl 4.0 patch 12.68decaef0a(June 8, 1992 — Larry Wall): Added$PID{$next}tracking andwaitpid($pid, 0)oncloseinperl 4.0 patch 22.f97f1ee016(March 17, 1996 — Perl 5 Porters): Attempted to fix the Linux/SVR4 socket constant collision by adding an unconditionalrequire 'sys/socket.ph';at the top oflib/chat2.plwhile moving# but who the heck would change these anyway? (:-)into theelsebranch—which promptly brokechat2.plon every system where the sysadmin had not runh2ph!a6d7165678(July 26, 1999 — Gurusamy Sarathy): Added a deprecation warning at the top oflib/chat2.pladvising users not to use it as an example of modern Perl programming techniques.50f338d87d(May 15, 2000 — Author: [Person/Randal Schwartz]], Committer: Jarkko Hietaniemi): During aperl5-portersdiscussion (Subject: Re: perlfaq8 coyness,Message-ID: <m166sfl0r9.fsf@halfdome.holdit.com>), I asked forchat2.plto finally be put out of its misery. Jarkko removed it in commit [50f338d87dwith the commit message:"Delete chat2 as requested by Randal."
- The
5. The
http://chat2.plPolish Domain Easter Egg & The 2026 Second Act- The 15-Year
.plDomain Quest & 2016 Lightning Talk:- On October 8, 2001, I sent an email titled
"an odd request"to Poland's.plcountry-code TLD registry (info@dns.pl), writing: "I'm the author of many Perl-related things. One in particular is the now obsolete 'chat2.pl' that was included with all copies of Perl4, and continues to haunt me even though it's never been supported. My friends agree that it'd be hilarious if I could get 'chat2.pl' as a domain name, and of course, that's where you come in." - After waiting nearly fifteen years for
.plregistration rules to open up, I finally registeredhttp://chat2.plvia Hover on March 7, 2016, pointed it straight to the originalPerl/perl5@11aea36008commit on GitHub, and emailed Larry Wall on March 16, 2016 (Subject: chat2.pl): "chat2.pl just got real: http://chat2.pl — Finally, after waiting 20 years for that domain name." - In June 2016, I delivered the lightning talk "The legacy of chat2.pl" at YAPC::NA 2016 (The Perl Conference) in Orlando, Florida—unveiling live on stage that
http://chat2.plresolved to the 1991 core commit.
- On October 8, 2001, I sent an email titled
- 1991–1994 Tools Built on
chat2.pl:- Beyond powering Lee McLoughlin's
ftp.plandmirrorfor CPAN, I usedchat2.plin my own early 1990s networking and aviation tools, includingftpr(91/08/16, a recursive regex-driven FTP mirror script),mypost(91/10/22, a single-process binary splitter, uuencoder, and NNTP poster), a Contel DUAT aviation weather briefing client (1993, fetching pre-flight weather briefings for Hillsboro AirportHIOover port 23), andnclip(1994, an NNTP keyword-clipping daemon modeled after Larry Wall'sclip).
- Beyond powering Lee McLoughlin's
- The 35-Year Arc to AI Agent Orchestration (2026): Thirty-five years after I named a guarded interactive subprocess supervisor
chat2.pl, the software industry adopted LLM "chat" interfaces—and repeated every mistakeexpectandchat2.plwere invented to solve (running conversational streams without invariant guards, timeouts, or explicit failure branches, while hardwiring happy-path assumptions like# but who the heck would change these anyway?). In October 2026, my Synthetic Scars and Smalltalk-80StateGrapharchitecture brought the guarded-pipe state-machine philosophy ofchat2.plfull circle to govern autonomous AI coding agents.
- The 15-Year
What links here
These facts are as Randal recalls them, but much time has passed for most of this. If you find a factual error, please email realmerlyn@gmail.com.