blank.gif (43 bytes)

Church Of The
Swimming Elephant

Perl Connected: An Internet Encyclopedia

Up: Connected: An Internet Encyclopedia
Up: Topics
Up: Software
Up: Languages
Prev: Java
Next: Mail



Perl, the Practical Extraction and Report Language, is Larry Wall's catch-all scripting language that has become nearly ubiquitous on UNIX systems. Of the many UNIX scripting languages available, Perl is the only one with built-in Internet networking support. For example, here a short script (taken verbatim from the Perl manual page), that implements a simple Internet server, which listens for TCP connections on port 2345 and prints anything it receives on standard output:


   ($port) = @ARGV;
   $port = 2345 unless $port;

   require 'sys/';

   $sockaddr = 'S n a4 x8';

   ($name, $aliases, $proto) = getprotobyname('tcp');
   ($name, $aliases, $port) = getservbyname($port, 'tcp')
        unless $port =~ /^\d+$/;

   $this = pack($sockaddr, &AF_INET, $port, "\0\0\0\0");

   select(NS); $| = 1; select(stdout);

   socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!";
   bind(S, $this) || die "bind: $!";
   listen(S, 5) || die "connect: $!";

   select(S); $| = 1; select(stdout);

   for (;;) {
        print "Listening again\n";
        ($addr = accept(NS,S)) || die $!;
        print "accept ok\n";

        ($af,$port,$inetaddr) = unpack($sockaddr,$addr);
        @inetaddr = unpack('C4',$inetaddr);
        print "$af $port @inetaddr\n";

        while () {
             print NS;

An online version of the Perl manual best describes how to use it. Tom Christenson maintains the Perl Language Home Page, and Yahoo has a Perl page.

Next: Mail

Connected: An Internet Encyclopedia


Protect yourself from cyberstalkers, identity thieves, and those who would snoop on you.
Stop spam from invading your inbox without losing the mail you want. We give you more control over your e-mail than any other service.
Block popups, ads, and malicious scripts while you surf the net through our anonymous proxies.
Participate in Usenet, host your web files, easily send anonymous messages, and more, much more.
All private, all encrypted, all secure, all in an easy to use service, and all for only $5.95 a month!

Service Details

Have you gone to church today?
All pages ©1999, 2000, 2001, 2002, 2003 Church of the Swimming Elephant unless otherwise stated
Church of the Swimming Elephant©1999, 2000, 2001, 2002, 2003 is a wholly owned subsidiary of Packetderm, LLC.

Packetderm, LLC
210 Park Ave #308
Worcester, MA 01609