Regular Expressions   «Prev 

Alternate Matches using Perl

Here is an example of alternate matches:
/[Ww](einman|eb[Mm]onster)/

The above matches two forms of my name. The pipe character (|) separates the two alternatives. Accordingly, Weinman and Webmonster will be matched. For that matter, all of the following names will be matched:
Weinman
weinman
WebMonster
webMonster
Webmonster
webmonster

Parenthesis are commonly used to enclose the alternatives, and they are indeed necessary in most circumstances.
Now let us apply this to our yes/no if structure:

if($input=~/^([Yy])|([Yy])es\b/
   { print "Let us play!\n" }
else
   { print "Okay. Thanks anyway.\n" }

The "or" structure (|) allows the script to match Y, y, Yes, or yes.

How Programs Communicate

Programs can communicate with each other in a variety of ways. They can use files, anonymous/named pipes, System V inter-process messaging primitives, BSD sockets, and TLI (Transport Layer Interface). Socket and TLI communications come under the purview of "networking," a step up from the other IPC (inter-process communication) mechanisms, because they do not constrain the communicating processes to be on the same machine.
This module provides a primer on socket communications and builds simple client/server configurations using Graham Barr's IO library (part of the standard Perl distribution). This knowledge is put to use in the next module, where we build an asynchronous message passing module, and another for doing remote procedure calls (RPC). Networking is the second of four important technologies that we discuss in this course. The others are 1) user interfaces, 2) persistence, and 3) code generation. This module is as much about the technology as it is about Perl's support for networking. Andrew Tanenbaum's textbook on computer networks is a wonderful introduction to computer networking.

Advanced Perl Programming