Currently At: Internet Encyclopedia > Software > Languages > Perl



Perl

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:

     #!/usr/bin/perl       ($port) = @ARGV;     $port = 2345 unless $port;       require 'sys/socket.ph';       $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 (NS>) {               print;               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.




Web Standards & Support:

Link to and support eLook.org Powered by LoadedWeb Web Hosting
Valid XHTML 1.0! Valid CSS! eLook.org FireFox Extensions