Chapter 22. Portable Perl

A world with only one operating system makes portability easy and life boring. We prefer a larger genetic pool of operating systems, as long as the ecosystem doesn’t divide too cleanly into predators and prey. Perl runs on dozens of operating systems, and because Perl programs aren’t platform dependent, the same program can run on all of those systems without modification.

Well, almost. Perl tries to give the programmer as many features as possible, but if you make use of features particular to a certain operating system, you’ll necessarily reduce the portability of your program to other systems. In this section we’ll provide some guidelines for writing portable Perl code. Once you make a decision about how portable you want to be, you’ll know where the lines are drawn, and you can stay within them.

Looking at it another way, writing portable code is usually about willfully limiting your available choices. Naturally, it takes discipline and sacrifice to do that, two traits that Perl programmers might be unaccustomed to.

The perlport manpage lists the platforms that Perl no longer supports, such as Mac OS 9 (Classic) and Windows 95, 98, ME, and NT4. Not only are they unsupported, but the code that formerly supported them has disappeared from the codebase. So, depending on your Perl, you may not have to support those anymore. Supported systems with deviations or special cases get their own manpage, as listed in Table 22-1.

Table 22-1. System-specific manpages ...

Get Programming Perl, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.