Perl for Multitasking and Networking
Introduction
In multitasking, the program performs several tasks at once. Multitasking is closely related to networking where we have to handle several events or serve several clients at once.
Technologies of Interest
IPC-Run
A module that allows one to run background processes with piping, and ptys. Works on UNIXes as well as Windows.
Expect
Allows one to control a terminal application interactively and wait for events.
Parallel-Map and Parallel-ForkManager
Provide simple ways to parallelise tasks. Also see Parallel-Map-Segmented and Parallel-ForkManager-Segmented.
Event Driven Programming Frameworks
There are several frameworks available for event driven programming, cooperative multitasking and writing network applications. You can find the most important and most recommended ones on CPAN. Here is a list of some of the most recommended ones.
POE: Perl Object Environment
POE was one of the first event-driven programming frameworks for Perl, and gained some popularity in part due to lack of alternatives. Its style is baroque and as such it may no longer be recommended.
IO-Async
A popular framework for asynchronous events on CPAN.
Discouraged Event Frameworks
AnyEvent
Note: Using AnyEvent is discouraged.
AnyEvent is a more modern events’ framework and allows one to make use of extensions for other frameworks. It is also fast.
Asynchronous Programming For-the-Win! - by Sawyer X. Slides for a talk with some examples.
Threads?
Many people are tempted to use threads with Perl and Internet forums are constantly frequented for help with threads in Perl. However, the use of threads in Perl is not recommended:
- Elizabeth Mattijsen has written an essay about the problems with threads in Perl on Perlmonks.
- See perlthrtut for more information.