Networking and IPC

If there’s a way that programs on your machine can talk with others, Perl can probably do it. This section shows some common ways.

System V IPC

The standard functions for System V IPC (interprocess communication) are all supported by Perl, so you can use message queues, semaphores, and shared memory. An array in Perl isn’t stored in a chunk of memory in the same way[387] that an array is stored in C, so shared memory can’t share Perl data as is. But there are modules that will translate data, so you can pretend that your Perl data is in shared memory. See the perlfunc manpage and the perlipc module.

Sockets

Perl has full support for TCP/IP sockets, which means that you could write a web server in Perl, or a web browser, Usenet news server or client, finger daemon or client, FTP daemon or client, SMTP or POP or SOAP server or client, or either end of pretty much any other kind of protocol in use on the Internet. You don’t need to get into the low-level details because there are modules available for all of the common protocols. For example, you can make a web server or client with the LWP module and one or two lines of additional code.[388] The LWP module (a tightly integrated set of modules, which implement nearly everything that happens on the Web) is a great example of high-quality Perl code, if you’d like to copy from the best. For other protocols, search for a module with the protocol’s name.

[387] It would be a lie to say that a Perl array is stored in “a chunk ...

Get Learning Perl, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.