1PERLPORT(1) Perl Programmers Reference Guide PERLPORT(1)
2
3
4
6 perlport - Writing portable Perl
7
9 Perl runs on numerous operating systems. While most of them share much
10 in common, they also have their own unique features.
11
12 This document is meant to help you to find out what constitutes
13 portable Perl code. That way once you make a decision to write
14 portably, you know where the lines are drawn, and you can stay within
15 them.
16
17 There is a tradeoff between taking full advantage of one particular
18 type of computer and taking advantage of a full range of them.
19 Naturally, as you broaden your range and become more diverse, the
20 common factors drop, and you are left with an increasingly smaller area
21 of common ground in which you can operate to accomplish a particular
22 task. Thus, when you begin attacking a problem, it is important to
23 consider under which part of the tradeoff curve you want to operate.
24 Specifically, you must decide whether it is important that the task
25 that you are coding have the full generality of being portable, or
26 whether to just get the job done right now. This is the hardest choice
27 to be made. The rest is easy, because Perl provides many choices,
28 whichever way you want to approach your problem.
29
30 Looking at it another way, writing portable code is usually about
31 willfully limiting your available choices. Naturally, it takes
32 discipline and sacrifice to do that. The product of portability and
33 convenience may be a constant. You have been warned.
34
35 Be aware of two important points:
36
37 Not all Perl programs have to be portable
38 There is no reason you should not use Perl as a language to glue
39 Unix tools together, or to prototype a Macintosh application, or to
40 manage the Windows registry. If it makes no sense to aim for
41 portability for one reason or another in a given program, then
42 don't bother.
43
44 Nearly all of Perl already is portable
45 Don't be fooled into thinking that it is hard to create portable
46 Perl code. It isn't. Perl tries its level-best to bridge the gaps
47 between what's available on different platforms, and all the means
48 available to use those features. Thus almost all Perl code runs on
49 any machine without modification. But there are some significant
50 issues in writing portable code, and this document is entirely
51 about those issues.
52
53 Here's the general rule: When you approach a task commonly done using a
54 whole range of platforms, think about writing portable code. That way,
55 you don't sacrifice much by way of the implementation choices you can
56 avail yourself of, and at the same time you can give your users lots of
57 platform choices. On the other hand, when you have to take advantage
58 of some unique feature of a particular platform, as is often the case
59 with systems programming (whether for Unix, Windows, VMS, etc.),
60 consider writing platform-specific code.
61
62 When the code will run on only two or three operating systems, you may
63 need to consider only the differences of those particular systems. The
64 important thing is to decide where the code will run and to be
65 deliberate in your decision.
66
67 The material below is separated into three main sections: main issues
68 of portability ("ISSUES"), platform-specific issues ("PLATFORMS"), and
69 built-in perl functions that behave differently on various ports
70 ("FUNCTION IMPLEMENTATIONS").
71
72 This information should not be considered complete; it includes
73 possibly transient information about idiosyncrasies of some of the
74 ports, almost all of which are in a state of constant evolution. Thus,
75 this material should be considered a perpetual work in progress ("<IMG
76 SRC="yellow_sign.gif" ALT="Under Construction">").
77
79 Newlines
80 In most operating systems, lines in files are terminated by newlines.
81 Just what is used as a newline may vary from OS to OS. Unix
82 traditionally uses "\012", one type of DOSish I/O uses "\015\012", and
83 Mac OS uses "\015".
84
85 Perl uses "\n" to represent the "logical" newline, where what is
86 logical may depend on the platform in use. In MacPerl, "\n" always
87 means "\015". In DOSish perls, "\n" usually means "\012", but when
88 accessing a file in "text" mode, perl uses the ":crlf" layer that
89 translates it to (or from) "\015\012", depending on whether you're
90 reading or writing. Unix does the same thing on ttys in canonical mode.
91 "\015\012" is commonly referred to as CRLF.
92
93 To trim trailing newlines from text lines use chomp(). With default
94 settings that function looks for a trailing "\n" character and thus
95 trims in a portable way.
96
97 When dealing with binary files (or text files in binary mode) be sure
98 to explicitly set $/ to the appropriate value for your file format
99 before using chomp().
100
101 Because of the "text" mode translation, DOSish perls have limitations
102 in using "seek" and "tell" on a file accessed in "text" mode. Stick to
103 "seek"-ing to locations you got from "tell" (and no others), and you
104 are usually free to use "seek" and "tell" even in "text" mode. Using
105 "seek" or "tell" or other file operations may be non-portable. If you
106 use "binmode" on a file, however, you can usually "seek" and "tell"
107 with arbitrary values in safety.
108
109 A common misconception in socket programming is that "\n" eq "\012"
110 everywhere. When using protocols such as common Internet protocols,
111 "\012" and "\015" are called for specifically, and the values of the
112 logical "\n" and "\r" (carriage return) are not reliable.
113
114 print SOCKET "Hi there, client!\r\n"; # WRONG
115 print SOCKET "Hi there, client!\015\012"; # RIGHT
116
117 However, using "\015\012" (or "\cM\cJ", or "\x0D\x0A") can be tedious
118 and unsightly, as well as confusing to those maintaining the code. As
119 such, the Socket module supplies the Right Thing for those who want it.
120
121 use Socket qw(:DEFAULT :crlf);
122 print SOCKET "Hi there, client!$CRLF" # RIGHT
123
124 When reading from a socket, remember that the default input record
125 separator $/ is "\n", but robust socket code will recognize as either
126 "\012" or "\015\012" as end of line:
127
128 while (<SOCKET>) {
129 # ...
130 }
131
132 Because both CRLF and LF end in LF, the input record separator can be
133 set to LF and any CR stripped later. Better to write:
134
135 use Socket qw(:DEFAULT :crlf);
136 local($/) = LF; # not needed if $/ is already \012
137
138 while (<SOCKET>) {
139 s/$CR?$LF/\n/; # not sure if socket uses LF or CRLF, OK
140 # s/\015?\012/\n/; # same thing
141 }
142
143 This example is preferred over the previous one--even for Unix
144 platforms--because now any "\015"'s ("\cM"'s) are stripped out (and
145 there was much rejoicing).
146
147 Similarly, functions that return text data--such as a function that
148 fetches a web page--should sometimes translate newlines before
149 returning the data, if they've not yet been translated to the local
150 newline representation. A single line of code will often suffice:
151
152 $data =~ s/\015?\012/\n/g;
153 return $data;
154
155 Some of this may be confusing. Here's a handy reference to the ASCII
156 CR and LF characters. You can print it out and stick it in your
157 wallet.
158
159 LF eq \012 eq \x0A eq \cJ eq chr(10) eq ASCII 10
160 CR eq \015 eq \x0D eq \cM eq chr(13) eq ASCII 13
161
162 | Unix | DOS | Mac |
163 ---------------------------
164 \n | LF | LF | CR |
165 \r | CR | CR | LF |
166 \n * | LF | CRLF | CR |
167 \r * | CR | CR | LF |
168 ---------------------------
169 * text-mode STDIO
170
171 The Unix column assumes that you are not accessing a serial line (like
172 a tty) in canonical mode. If you are, then CR on input becomes "\n",
173 and "\n" on output becomes CRLF.
174
175 These are just the most common definitions of "\n" and "\r" in Perl.
176 There may well be others. For example, on an EBCDIC implementation
177 such as z/OS (OS/390) or OS/400 (using the ILE, the PASE is ASCII-
178 based) the above material is similar to "Unix" but the code numbers
179 change:
180
181 LF eq \025 eq \x15 eq \cU eq chr(21) eq CP-1047 21
182 LF eq \045 eq \x25 eq chr(37) eq CP-0037 37
183 CR eq \015 eq \x0D eq \cM eq chr(13) eq CP-1047 13
184 CR eq \015 eq \x0D eq \cM eq chr(13) eq CP-0037 13
185
186 | z/OS | OS/400 |
187 ----------------------
188 \n | LF | LF |
189 \r | CR | CR |
190 \n * | LF | LF |
191 \r * | CR | CR |
192 ----------------------
193 * text-mode STDIO
194
195 Numbers endianness and Width
196 Different CPUs store integers and floating point numbers in different
197 orders (called endianness) and widths (32-bit and 64-bit being the most
198 common today). This affects your programs when they attempt to
199 transfer numbers in binary format from one CPU architecture to another,
200 usually either "live" via network connection, or by storing the numbers
201 to secondary storage such as a disk file or tape.
202
203 Conflicting storage orders make utter mess out of the numbers. If a
204 little-endian host (Intel, VAX) stores 0x12345678 (305419896 in
205 decimal), a big-endian host (Motorola, Sparc, PA) reads it as
206 0x78563412 (2018915346 in decimal). Alpha and MIPS can be either:
207 Digital/Compaq used/uses them in little-endian mode; SGI/Cray uses them
208 in big-endian mode. To avoid this problem in network (socket)
209 connections use the "pack" and "unpack" formats "n" and "N", the
210 "network" orders. These are guaranteed to be portable.
211
212 As of perl 5.9.2, you can also use the ">" and "<" modifiers to force
213 big- or little-endian byte-order. This is useful if you want to store
214 signed integers or 64-bit integers, for example.
215
216 You can explore the endianness of your platform by unpacking a data
217 structure packed in native format such as:
218
219 print unpack("h*", pack("s2", 1, 2)), "\n";
220 # '10002000' on e.g. Intel x86 or Alpha 21064 in little-endian mode
221 # '00100020' on e.g. Motorola 68040
222
223 If you need to distinguish between endian architectures you could use
224 either of the variables set like so:
225
226 $is_big_endian = unpack("h*", pack("s", 1)) =~ /01/;
227 $is_little_endian = unpack("h*", pack("s", 1)) =~ /^1/;
228
229 Differing widths can cause truncation even between platforms of equal
230 endianness. The platform of shorter width loses the upper parts of the
231 number. There is no good solution for this problem except to avoid
232 transferring or storing raw binary numbers.
233
234 One can circumnavigate both these problems in two ways. Either
235 transfer and store numbers always in text format, instead of raw
236 binary, or else consider using modules like Data::Dumper (included in
237 the standard distribution as of Perl 5.005) and Storable (included as
238 of perl 5.8). Keeping all data as text significantly simplifies
239 matters.
240
241 The v-strings are portable only up to v2147483647 (0x7FFFFFFF), that's
242 how far EBCDIC, or more precisely UTF-EBCDIC will go.
243
244 Files and Filesystems
245 Most platforms these days structure files in a hierarchical fashion.
246 So, it is reasonably safe to assume that all platforms support the
247 notion of a "path" to uniquely identify a file on the system. How that
248 path is really written, though, differs considerably.
249
250 Although similar, file path specifications differ between Unix,
251 Windows, Mac OS, OS/2, VMS, VOS, RISC OS, and probably others. Unix,
252 for example, is one of the few OSes that has the elegant idea of a
253 single root directory.
254
255 DOS, OS/2, VMS, VOS, and Windows can work similarly to Unix with "/" as
256 path separator, or in their own idiosyncratic ways (such as having
257 several root directories and various "unrooted" device files such NIL:
258 and LPT:).
259
260 Mac OS 9 and earlier used ":" as a path separator instead of "/".
261
262 The filesystem may support neither hard links ("link") nor symbolic
263 links ("symlink", "readlink", "lstat").
264
265 The filesystem may support neither access timestamp nor change
266 timestamp (meaning that about the only portable timestamp is the
267 modification timestamp), or one second granularity of any timestamps
268 (e.g. the FAT filesystem limits the time granularity to two seconds).
269
270 The "inode change timestamp" (the "-C" filetest) may really be the
271 "creation timestamp" (which it is not in Unix).
272
273 VOS perl can emulate Unix filenames with "/" as path separator. The
274 native pathname characters greater-than, less-than, number-sign, and
275 percent-sign are always accepted.
276
277 RISC OS perl can emulate Unix filenames with "/" as path separator, or
278 go native and use "." for path separator and ":" to signal filesystems
279 and disk names.
280
281 Don't assume Unix filesystem access semantics: that read, write, and
282 execute are all the permissions there are, and even if they exist, that
283 their semantics (for example what do r, w, and x mean on a directory)
284 are the Unix ones. The various Unix/POSIX compatibility layers usually
285 try to make interfaces like chmod() work, but sometimes there simply is
286 no good mapping.
287
288 If all this is intimidating, have no (well, maybe only a little) fear.
289 There are modules that can help. The File::Spec modules provide
290 methods to do the Right Thing on whatever platform happens to be
291 running the program.
292
293 use File::Spec::Functions;
294 chdir(updir()); # go up one directory
295 my $file = catfile(curdir(), 'temp', 'file.txt');
296 # on Unix and Win32, './temp/file.txt'
297 # on Mac OS Classic, ':temp:file.txt'
298 # on VMS, '[.temp]file.txt'
299
300 File::Spec is available in the standard distribution as of version
301 5.004_05. File::Spec::Functions is only in File::Spec 0.7 and later,
302 and some versions of perl come with version 0.6. If File::Spec is not
303 updated to 0.7 or later, you must use the object-oriented interface
304 from File::Spec (or upgrade File::Spec).
305
306 In general, production code should not have file paths hardcoded.
307 Making them user-supplied or read from a configuration file is better,
308 keeping in mind that file path syntax varies on different machines.
309
310 This is especially noticeable in scripts like Makefiles and test
311 suites, which often assume "/" as a path separator for subdirectories.
312
313 Also of use is File::Basename from the standard distribution, which
314 splits a pathname into pieces (base filename, full path to directory,
315 and file suffix).
316
317 Even when on a single platform (if you can call Unix a single
318 platform), remember not to count on the existence or the contents of
319 particular system-specific files or directories, like /etc/passwd,
320 /etc/sendmail.conf, /etc/resolv.conf, or even /tmp/. For example,
321 /etc/passwd may exist but not contain the encrypted passwords, because
322 the system is using some form of enhanced security. Or it may not
323 contain all the accounts, because the system is using NIS. If code
324 does need to rely on such a file, include a description of the file and
325 its format in the code's documentation, then make it easy for the user
326 to override the default location of the file.
327
328 Don't assume a text file will end with a newline. They should, but
329 people forget.
330
331 Do not have two files or directories of the same name with different
332 case, like test.pl and Test.pl, as many platforms have case-insensitive
333 (or at least case-forgiving) filenames. Also, try not to have non-word
334 characters (except for ".") in the names, and keep them to the 8.3
335 convention, for maximum portability, onerous a burden though this may
336 appear.
337
338 Likewise, when using the AutoSplit module, try to keep your functions
339 to 8.3 naming and case-insensitive conventions; or, at the least, make
340 it so the resulting files have a unique (case-insensitively) first 8
341 characters.
342
343 Whitespace in filenames is tolerated on most systems, but not all, and
344 even on systems where it might be tolerated, some utilities might
345 become confused by such whitespace.
346
347 Many systems (DOS, VMS ODS-2) cannot have more than one "." in their
348 filenames.
349
350 Don't assume ">" won't be the first character of a filename. Always
351 use "<" explicitly to open a file for reading, or even better, use the
352 three-arg version of open, unless you want the user to be able to
353 specify a pipe open.
354
355 open my $fh, '<', $existing_file) or die $!;
356
357 If filenames might use strange characters, it is safest to open it with
358 "sysopen" instead of "open". "open" is magic and can translate
359 characters like ">", "<", and "|", which may be the wrong thing to do.
360 (Sometimes, though, it's the right thing.) Three-arg open can also
361 help protect against this translation in cases where it is undesirable.
362
363 Don't use ":" as a part of a filename since many systems use that for
364 their own semantics (Mac OS Classic for separating pathname components,
365 many networking schemes and utilities for separating the nodename and
366 the pathname, and so on). For the same reasons, avoid "@", ";" and
367 "|".
368
369 Don't assume that in pathnames you can collapse two leading slashes
370 "//" into one: some networking and clustering filesystems have special
371 semantics for that. Let the operating system to sort it out.
372
373 The portable filename characters as defined by ANSI C are
374
375 a b c d e f g h i j k l m n o p q r t u v w x y z
376 A B C D E F G H I J K L M N O P Q R T U V W X Y Z
377 0 1 2 3 4 5 6 7 8 9
378 . _ -
379
380 and the "-" shouldn't be the first character. If you want to be
381 hypercorrect, stay case-insensitive and within the 8.3 naming
382 convention (all the files and directories have to be unique within one
383 directory if their names are lowercased and truncated to eight
384 characters before the ".", if any, and to three characters after the
385 ".", if any). (And do not use "."s in directory names.)
386
387 System Interaction
388 Not all platforms provide a command line. These are usually platforms
389 that rely primarily on a Graphical User Interface (GUI) for user
390 interaction. A program requiring a command line interface might not
391 work everywhere. This is probably for the user of the program to deal
392 with, so don't stay up late worrying about it.
393
394 Some platforms can't delete or rename files held open by the system,
395 this limitation may also apply to changing filesystem metainformation
396 like file permissions or owners. Remember to "close" files when you
397 are done with them. Don't "unlink" or "rename" an open file. Don't
398 "tie" or "open" a file already tied or opened; "untie" or "close" it
399 first.
400
401 Don't open the same file more than once at a time for writing, as some
402 operating systems put mandatory locks on such files.
403
404 Don't assume that write/modify permission on a directory gives the
405 right to add or delete files/directories in that directory. That is
406 filesystem specific: in some filesystems you need write/modify
407 permission also (or even just) in the file/directory itself. In some
408 filesystems (AFS, DFS) the permission to add/delete directory entries
409 is a completely separate permission.
410
411 Don't assume that a single "unlink" completely gets rid of the file:
412 some filesystems (most notably the ones in VMS) have versioned
413 filesystems, and unlink() removes only the most recent one (it doesn't
414 remove all the versions because by default the native tools on those
415 platforms remove just the most recent version, too). The portable
416 idiom to remove all the versions of a file is
417
418 1 while unlink "file";
419
420 This will terminate if the file is undeleteable for some reason
421 (protected, not there, and so on).
422
423 Don't count on a specific environment variable existing in %ENV. Don't
424 count on %ENV entries being case-sensitive, or even case-preserving.
425 Don't try to clear %ENV by saying "%ENV = ();", or, if you really have
426 to, make it conditional on "$^O ne 'VMS'" since in VMS the %ENV table
427 is much more than a per-process key-value string table.
428
429 On VMS, some entries in the %ENV hash are dynamically created when
430 their key is used on a read if they did not previously exist. The
431 values for $ENV{HOME}, $ENV{TERM}, $ENV{HOME}, and $ENV{USER}, are
432 known to be dynamically generated. The specific names that are
433 dynamically generated may vary with the version of the C library on
434 VMS, and more may exist than is documented.
435
436 On VMS by default, changes to the %ENV hash are persistent after the
437 process exits. This can cause unintended issues.
438
439 Don't count on signals or %SIG for anything.
440
441 Don't count on filename globbing. Use "opendir", "readdir", and
442 "closedir" instead.
443
444 Don't count on per-program environment variables, or per-program
445 current directories.
446
447 Don't count on specific values of $!, neither numeric nor especially
448 the strings values. Users may switch their locales causing error
449 messages to be translated into their languages. If you can trust a
450 POSIXish environment, you can portably use the symbols defined by the
451 Errno module, like ENOENT. And don't trust on the values of $! at all
452 except immediately after a failed system call.
453
454 Command names versus file pathnames
455 Don't assume that the name used to invoke a command or program with
456 "system" or "exec" can also be used to test for the existence of the
457 file that holds the executable code for that command or program.
458 First, many systems have "internal" commands that are built-in to the
459 shell or OS and while these commands can be invoked, there is no
460 corresponding file. Second, some operating systems (e.g., Cygwin,
461 DJGPP, OS/2, and VOS) have required suffixes for executable files;
462 these suffixes are generally permitted on the command name but are not
463 required. Thus, a command like "perl" might exist in a file named
464 "perl", "perl.exe", or "perl.pm", depending on the operating system.
465 The variable "_exe" in the Config module holds the executable suffix,
466 if any. Third, the VMS port carefully sets up $^X and
467 $Config{perlpath} so that no further processing is required. This is
468 just as well, because the matching regular expression used below would
469 then have to deal with a possible trailing version number in the VMS
470 file name.
471
472 To convert $^X to a file pathname, taking account of the requirements
473 of the various operating system possibilities, say:
474
475 use Config;
476 my $thisperl = $^X;
477 if ($^O ne 'VMS')
478 {$thisperl .= $Config{_exe} unless $thisperl =~ m/$Config{_exe}$/i;}
479
480 To convert $Config{perlpath} to a file pathname, say:
481
482 use Config;
483 my $thisperl = $Config{perlpath};
484 if ($^O ne 'VMS')
485 {$thisperl .= $Config{_exe} unless $thisperl =~ m/$Config{_exe}$/i;}
486
487 Networking
488 Don't assume that you can reach the public Internet.
489
490 Don't assume that there is only one way to get through firewalls to the
491 public Internet.
492
493 Don't assume that you can reach outside world through any other port
494 than 80, or some web proxy. ftp is blocked by many firewalls.
495
496 Don't assume that you can send email by connecting to the local SMTP
497 port.
498
499 Don't assume that you can reach yourself or any node by the name
500 'localhost'. The same goes for '127.0.0.1'. You will have to try
501 both.
502
503 Don't assume that the host has only one network card, or that it can't
504 bind to many virtual IP addresses.
505
506 Don't assume a particular network device name.
507
508 Don't assume a particular set of ioctl()s will work.
509
510 Don't assume that you can ping hosts and get replies.
511
512 Don't assume that any particular port (service) will respond.
513
514 Don't assume that Sys::Hostname (or any other API or command) returns
515 either a fully qualified hostname or a non-qualified hostname: it all
516 depends on how the system had been configured. Also remember that for
517 things such as DHCP and NAT, the hostname you get back might not be
518 very useful.
519
520 All the above "don't":s may look daunting, and they are, but the key is
521 to degrade gracefully if one cannot reach the particular network
522 service one wants. Croaking or hanging do not look very professional.
523
524 Interprocess Communication (IPC)
525 In general, don't directly access the system in code meant to be
526 portable. That means, no "system", "exec", "fork", "pipe", "``",
527 "qx//", "open" with a "|", nor any of the other things that makes being
528 a perl hacker worth being.
529
530 Commands that launch external processes are generally supported on most
531 platforms (though many of them do not support any type of forking).
532 The problem with using them arises from what you invoke them on.
533 External tools are often named differently on different platforms, may
534 not be available in the same location, might accept different
535 arguments, can behave differently, and often present their results in a
536 platform-dependent way. Thus, you should seldom depend on them to
537 produce consistent results. (Then again, if you're calling netstat -a,
538 you probably don't expect it to run on both Unix and CP/M.)
539
540 One especially common bit of Perl code is opening a pipe to sendmail:
541
542 open(MAIL, '|/usr/lib/sendmail -t')
543 or die "cannot fork sendmail: $!";
544
545 This is fine for systems programming when sendmail is known to be
546 available. But it is not fine for many non-Unix systems, and even some
547 Unix systems that may not have sendmail installed. If a portable
548 solution is needed, see the various distributions on CPAN that deal
549 with it. Mail::Mailer and Mail::Send in the MailTools distribution are
550 commonly used, and provide several mailing methods, including mail,
551 sendmail, and direct SMTP (via Net::SMTP) if a mail transfer agent is
552 not available. Mail::Sendmail is a standalone module that provides
553 simple, platform-independent mailing.
554
555 The Unix System V IPC ("msg*(), sem*(), shm*()") is not available even
556 on all Unix platforms.
557
558 Do not use either the bare result of "pack("N", 10, 20, 30, 40)" or
559 bare v-strings (such as "v10.20.30.40") to represent IPv4 addresses:
560 both forms just pack the four bytes into network order. That this
561 would be equal to the C language "in_addr" struct (which is what the
562 socket code internally uses) is not guaranteed. To be portable use the
563 routines of the Socket extension, such as "inet_aton()", "inet_ntoa()",
564 and "sockaddr_in()".
565
566 The rule of thumb for portable code is: Do it all in portable Perl, or
567 use a module (that may internally implement it with platform-specific
568 code, but expose a common interface).
569
570 External Subroutines (XS)
571 XS code can usually be made to work with any platform, but dependent
572 libraries, header files, etc., might not be readily available or
573 portable, or the XS code itself might be platform-specific, just as
574 Perl code might be. If the libraries and headers are portable, then it
575 is normally reasonable to make sure the XS code is portable, too.
576
577 A different type of portability issue arises when writing XS code:
578 availability of a C compiler on the end-user's system. C brings with
579 it its own portability issues, and writing XS code will expose you to
580 some of those. Writing purely in Perl is an easier way to achieve
581 portability.
582
583 Standard Modules
584 In general, the standard modules work across platforms. Notable
585 exceptions are the CPAN module (which currently makes connections to
586 external programs that may not be available), platform-specific modules
587 (like ExtUtils::MM_VMS), and DBM modules.
588
589 There is no one DBM module available on all platforms. SDBM_File and
590 the others are generally available on all Unix and DOSish ports, but
591 not in MacPerl, where only NBDM_File and DB_File are available.
592
593 The good news is that at least some DBM module should be available, and
594 AnyDBM_File will use whichever module it can find. Of course, then the
595 code needs to be fairly strict, dropping to the greatest common factor
596 (e.g., not exceeding 1K for each record), so that it will work with any
597 DBM module. See AnyDBM_File for more details.
598
599 Time and Date
600 The system's notion of time of day and calendar date is controlled in
601 widely different ways. Don't assume the timezone is stored in
602 $ENV{TZ}, and even if it is, don't assume that you can control the
603 timezone through that variable. Don't assume anything about the three-
604 letter timezone abbreviations (for example that MST would be the
605 Mountain Standard Time, it's been known to stand for Moscow Standard
606 Time). If you need to use timezones, express them in some unambiguous
607 format like the exact number of minutes offset from UTC, or the POSIX
608 timezone format.
609
610 Don't assume that the epoch starts at 00:00:00, January 1, 1970,
611 because that is OS- and implementation-specific. It is better to store
612 a date in an unambiguous representation. The ISO 8601 standard defines
613 YYYY-MM-DD as the date format, or YYYY-MM-DDTHH-MM-SS (that's a literal
614 "T" separating the date from the time). Please do use the ISO 8601
615 instead of making us to guess what date 02/03/04 might be. ISO 8601
616 even sorts nicely as-is. A text representation (like "1987-12-18") can
617 be easily converted into an OS-specific value using a module like
618 Date::Parse. An array of values, such as those returned by
619 "localtime", can be converted to an OS-specific representation using
620 Time::Local.
621
622 When calculating specific times, such as for tests in time or date
623 modules, it may be appropriate to calculate an offset for the epoch.
624
625 require Time::Local;
626 my $offset = Time::Local::timegm(0, 0, 0, 1, 0, 70);
627
628 The value for $offset in Unix will be 0, but in Mac OS Classic will be
629 some large number. $offset can then be added to a Unix time value to
630 get what should be the proper value on any system.
631
632 Character sets and character encoding
633 Assume very little about character sets.
634
635 Assume nothing about numerical values ("ord", "chr") of characters. Do
636 not use explicit code point ranges (like \xHH-\xHH); use for example
637 symbolic character classes like "[:print:]".
638
639 Do not assume that the alphabetic characters are encoded contiguously
640 (in the numeric sense). There may be gaps.
641
642 Do not assume anything about the ordering of the characters. The
643 lowercase letters may come before or after the uppercase letters; the
644 lowercase and uppercase may be interlaced so that both "a" and "A" come
645 before "b"; the accented and other international characters may be
646 interlaced so that ae comes before "b".
647
648 Internationalisation
649 If you may assume POSIX (a rather large assumption), you may read more
650 about the POSIX locale system from perllocale. The locale system at
651 least attempts to make things a little bit more portable, or at least
652 more convenient and native-friendly for non-English users. The system
653 affects character sets and encoding, and date and time
654 formatting--amongst other things.
655
656 If you really want to be international, you should consider Unicode.
657 See perluniintro and perlunicode for more information.
658
659 If you want to use non-ASCII bytes (outside the bytes 0x00..0x7f) in
660 the "source code" of your code, to be portable you have to be explicit
661 about what bytes they are. Someone might for example be using your
662 code under a UTF-8 locale, in which case random native bytes might be
663 illegal ("Malformed UTF-8 ...") This means that for example embedding
664 ISO 8859-1 bytes beyond 0x7f into your strings might cause trouble
665 later. If the bytes are native 8-bit bytes, you can use the "bytes"
666 pragma. If the bytes are in a string (regular expression being a
667 curious string), you can often also use the "\xHH" notation instead of
668 embedding the bytes as-is. (If you want to write your code in UTF-8,
669 you can use the "utf8".) The "bytes" and "utf8" pragmata are available
670 since Perl 5.6.0.
671
672 System Resources
673 If your code is destined for systems with severely constrained (or
674 missing!) virtual memory systems then you want to be especially mindful
675 of avoiding wasteful constructs such as:
676
677 # NOTE: this is no longer "bad" in perl5.005
678 for (0..10000000) {} # bad
679 for (my $x = 0; $x <= 10000000; ++$x) {} # good
680
681 my @lines = <$very_large_file>; # bad
682
683 while (<$fh>) {$file .= $_} # sometimes bad
684 my $file = join('', <$fh>); # better
685
686 The last two constructs may appear unintuitive to most people. The
687 first repeatedly grows a string, whereas the second allocates a large
688 chunk of memory in one go. On some systems, the second is more
689 efficient that the first.
690
691 Security
692 Most multi-user platforms provide basic levels of security, usually
693 implemented at the filesystem level. Some, however, unfortunately do
694 not. Thus the notion of user id, or "home" directory, or even the
695 state of being logged-in, may be unrecognizable on many platforms. If
696 you write programs that are security-conscious, it is usually best to
697 know what type of system you will be running under so that you can
698 write code explicitly for that platform (or class of platforms).
699
700 Don't assume the Unix filesystem access semantics: the operating system
701 or the filesystem may be using some ACL systems, which are richer
702 languages than the usual rwx. Even if the rwx exist, their semantics
703 might be different.
704
705 (From security viewpoint testing for permissions before attempting to
706 do something is silly anyway: if one tries this, there is potential for
707 race conditions. Someone or something might change the permissions
708 between the permissions check and the actual operation. Just try the
709 operation.)
710
711 Don't assume the Unix user and group semantics: especially, don't
712 expect the $< and $> (or the $( and $)) to work for switching
713 identities (or memberships).
714
715 Don't assume set-uid and set-gid semantics. (And even if you do, think
716 twice: set-uid and set-gid are a known can of security worms.)
717
718 Style
719 For those times when it is necessary to have platform-specific code,
720 consider keeping the platform-specific code in one place, making
721 porting to other platforms easier. Use the Config module and the
722 special variable $^O to differentiate platforms, as described in
723 "PLATFORMS".
724
725 Be careful in the tests you supply with your module or programs.
726 Module code may be fully portable, but its tests might not be. This
727 often happens when tests spawn off other processes or call external
728 programs to aid in the testing, or when (as noted above) the tests
729 assume certain things about the filesystem and paths. Be careful not
730 to depend on a specific output style for errors, such as when checking
731 $! after a failed system call. Using $! for anything else than
732 displaying it as output is doubtful (though see the Errno module for
733 testing reasonably portably for error value). Some platforms expect a
734 certain output format, and Perl on those platforms may have been
735 adjusted accordingly. Most specifically, don't anchor a regex when
736 testing an error value.
737
739 Modules uploaded to CPAN are tested by a variety of volunteers on
740 different platforms. These CPAN testers are notified by mail of each
741 new upload, and reply to the list with PASS, FAIL, NA (not applicable
742 to this platform), or UNKNOWN (unknown), along with any relevant
743 notations.
744
745 The purpose of the testing is twofold: one, to help developers fix any
746 problems in their code that crop up because of lack of testing on other
747 platforms; two, to provide users with information about whether a given
748 module works on a given platform.
749
750 Also see:
751
752 · Mailing list: cpan-testers@perl.org
753
754 · Testing results: http://testers.cpan.org/
755
757 As of version 5.002, Perl is built with a $^O variable that indicates
758 the operating system it was built on. This was implemented to help
759 speed up code that would otherwise have to "use Config" and use the
760 value of $Config{osname}. Of course, to get more detailed information
761 about the system, looking into %Config is certainly recommended.
762
763 %Config cannot always be trusted, however, because it was built at
764 compile time. If perl was built in one place, then transferred
765 elsewhere, some values may be wrong. The values may even have been
766 edited after the fact.
767
768 Unix
769 Perl works on a bewildering variety of Unix and Unix-like platforms
770 (see e.g. most of the files in the hints/ directory in the source code
771 kit). On most of these systems, the value of $^O (hence
772 $Config{'osname'}, too) is determined either by lowercasing and
773 stripping punctuation from the first field of the string returned by
774 typing "uname -a" (or a similar command) at the shell prompt or by
775 testing the file system for the presence of uniquely named files such
776 as a kernel or header file. Here, for example, are a few of the more
777 popular Unix flavors:
778
779 uname $^O $Config{'archname'}
780 --------------------------------------------
781 AIX aix aix
782 BSD/OS bsdos i386-bsdos
783 Darwin darwin darwin
784 dgux dgux AViiON-dgux
785 DYNIX/ptx dynixptx i386-dynixptx
786 FreeBSD freebsd freebsd-i386
787 Haiku haiku BePC-haiku
788 Linux linux arm-linux
789 Linux linux i386-linux
790 Linux linux i586-linux
791 Linux linux ppc-linux
792 HP-UX hpux PA-RISC1.1
793 IRIX irix irix
794 Mac OS X darwin darwin
795 NeXT 3 next next-fat
796 NeXT 4 next OPENSTEP-Mach
797 openbsd openbsd i386-openbsd
798 OSF1 dec_osf alpha-dec_osf
799 reliantunix-n svr4 RM400-svr4
800 SCO_SV sco_sv i386-sco_sv
801 SINIX-N svr4 RM400-svr4
802 sn4609 unicos CRAY_C90-unicos
803 sn6521 unicosmk t3e-unicosmk
804 sn9617 unicos CRAY_J90-unicos
805 SunOS solaris sun4-solaris
806 SunOS solaris i86pc-solaris
807 SunOS4 sunos sun4-sunos
808
809 Because the value of $Config{archname} may depend on the hardware
810 architecture, it can vary more than the value of $^O.
811
812 DOS and Derivatives
813 Perl has long been ported to Intel-style microcomputers running under
814 systems like PC-DOS, MS-DOS, OS/2, and most Windows platforms you can
815 bring yourself to mention (except for Windows CE, if you count that).
816 Users familiar with COMMAND.COM or CMD.EXE style shells should be aware
817 that each of these file specifications may have subtle differences:
818
819 my $filespec0 = "c:/foo/bar/file.txt";
820 my $filespec1 = "c:\\foo\\bar\\file.txt";
821 my $filespec2 = 'c:\foo\bar\file.txt';
822 my $filespec3 = 'c:\\foo\\bar\\file.txt';
823
824 System calls accept either "/" or "\" as the path separator. However,
825 many command-line utilities of DOS vintage treat "/" as the option
826 prefix, so may get confused by filenames containing "/". Aside from
827 calling any external programs, "/" will work just fine, and probably
828 better, as it is more consistent with popular usage, and avoids the
829 problem of remembering what to backwhack and what not to.
830
831 The DOS FAT filesystem can accommodate only "8.3" style filenames.
832 Under the "case-insensitive, but case-preserving" HPFS (OS/2) and NTFS
833 (NT) filesystems you may have to be careful about case returned with
834 functions like "readdir" or used with functions like "open" or
835 "opendir".
836
837 DOS also treats several filenames as special, such as AUX, PRN, NUL,
838 CON, COM1, LPT1, LPT2, etc. Unfortunately, sometimes these filenames
839 won't even work if you include an explicit directory prefix. It is
840 best to avoid such filenames, if you want your code to be portable to
841 DOS and its derivatives. It's hard to know what these all are,
842 unfortunately.
843
844 Users of these operating systems may also wish to make use of scripts
845 such as pl2bat.bat or pl2cmd to put wrappers around your scripts.
846
847 Newline ("\n") is translated as "\015\012" by STDIO when reading from
848 and writing to files (see "Newlines"). "binmode(FILEHANDLE)" will keep
849 "\n" translated as "\012" for that filehandle. Since it is a no-op on
850 other systems, "binmode" should be used for cross-platform code that
851 deals with binary data. That's assuming you realize in advance that
852 your data is in binary. General-purpose programs should often assume
853 nothing about their data.
854
855 The $^O variable and the $Config{archname} values for various DOSish
856 perls are as follows:
857
858 OS $^O $Config{archname} ID Version
859 --------------------------------------------------------
860 MS-DOS dos ?
861 PC-DOS dos ?
862 OS/2 os2 ?
863 Windows 3.1 ? ? 0 3 01
864 Windows 95 MSWin32 MSWin32-x86 1 4 00
865 Windows 98 MSWin32 MSWin32-x86 1 4 10
866 Windows ME MSWin32 MSWin32-x86 1 ?
867 Windows NT MSWin32 MSWin32-x86 2 4 xx
868 Windows NT MSWin32 MSWin32-ALPHA 2 4 xx
869 Windows NT MSWin32 MSWin32-ppc 2 4 xx
870 Windows 2000 MSWin32 MSWin32-x86 2 5 00
871 Windows XP MSWin32 MSWin32-x86 2 5 01
872 Windows 2003 MSWin32 MSWin32-x86 2 5 02
873 Windows Vista MSWin32 MSWin32-x86 2 6 00
874 Windows 7 MSWin32 MSWin32-x86 2 6 01
875 Windows 7 MSWin32 MSWin32-x64 2 6 01
876 Windows CE MSWin32 ? 3
877 Cygwin cygwin cygwin
878
879 The various MSWin32 Perl's can distinguish the OS they are running on
880 via the value of the fifth element of the list returned from
881 Win32::GetOSVersion(). For example:
882
883 if ($^O eq 'MSWin32') {
884 my @os_version_info = Win32::GetOSVersion();
885 print +('3.1','95','NT')[$os_version_info[4]],"\n";
886 }
887
888 There are also Win32::IsWinNT() and Win32::IsWin95(), try "perldoc
889 Win32", and as of libwin32 0.19 (not part of the core Perl
890 distribution) Win32::GetOSName(). The very portable POSIX::uname()
891 will work too:
892
893 c:\> perl -MPOSIX -we "print join '|', uname"
894 Windows NT|moonru|5.0|Build 2195 (Service Pack 2)|x86
895
896 Also see:
897
898 · The djgpp environment for DOS, http://www.delorie.com/djgpp/ and
899 perldos.
900
901 · The EMX environment for DOS, OS/2, etc. emx@iaehv.nl,
902 ftp://hobbes.nmsu.edu/pub/os2/dev/emx/ Also perlos2.
903
904 · Build instructions for Win32 in perlwin32, or under the Cygnus
905 environment in perlcygwin.
906
907 · The "Win32::*" modules in Win32.
908
909 · The ActiveState Pages, http://www.activestate.com/
910
911 · The Cygwin environment for Win32; README.cygwin (installed as
912 perlcygwin), http://www.cygwin.com/
913
914 · The U/WIN environment for Win32,
915 http://www.research.att.com/sw/tools/uwin/
916
917 · Build instructions for OS/2, perlos2
918
919 VMS
920 Perl on VMS is discussed in perlvms in the perl distribution.
921
922 The official name of VMS as of this writing is OpenVMS.
923
924 Perl on VMS can accept either VMS- or Unix-style file specifications as
925 in either of the following:
926
927 $ perl -ne "print if /perl_setup/i" SYS$LOGIN:LOGIN.COM
928 $ perl -ne "print if /perl_setup/i" /sys$login/login.com
929
930 but not a mixture of both as in:
931
932 $ perl -ne "print if /perl_setup/i" sys$login:/login.com
933 Can't open sys$login:/login.com: file specification syntax error
934
935 Interacting with Perl from the Digital Command Language (DCL) shell
936 often requires a different set of quotation marks than Unix shells do.
937 For example:
938
939 $ perl -e "print ""Hello, world.\n"""
940 Hello, world.
941
942 There are several ways to wrap your perl scripts in DCL .COM files, if
943 you are so inclined. For example:
944
945 $ write sys$output "Hello from DCL!"
946 $ if p1 .eqs. ""
947 $ then perl -x 'f$environment("PROCEDURE")
948 $ else perl -x - 'p1 'p2 'p3 'p4 'p5 'p6 'p7 'p8
949 $ deck/dollars="__END__"
950 #!/usr/bin/perl
951
952 print "Hello from Perl!\n";
953
954 __END__
955 $ endif
956
957 Do take care with "$ ASSIGN/nolog/user SYS$COMMAND: SYS$INPUT" if your
958 perl-in-DCL script expects to do things like "$read = <STDIN>;".
959
960 The VMS operating system has two filesystems, known as ODS-2 and ODS-5.
961
962 For ODS-2, filenames are in the format "name.extension;version". The
963 maximum length for filenames is 39 characters, and the maximum length
964 for extensions is also 39 characters. Version is a number from 1 to
965 32767. Valid characters are "/[A-Z0-9$_-]/".
966
967 The ODS-2 filesystem is case-insensitive and does not preserve case.
968 Perl simulates this by converting all filenames to lowercase
969 internally.
970
971 For ODS-5, filenames may have almost any character in them and can
972 include Unicode characters. Characters that could be misinterpreted by
973 the DCL shell or file parsing utilities need to be prefixed with the
974 "^" character, or replaced with hexadecimal characters prefixed with
975 the "^" character. Such prefixing is only needed with the pathnames
976 are in VMS format in applications. Programs that can accept the Unix
977 format of pathnames do not need the escape characters. The maximum
978 length for filenames is 255 characters. The ODS-5 file system can
979 handle both a case preserved and a case sensitive mode.
980
981 ODS-5 is only available on the OpenVMS for 64 bit platforms.
982
983 Support for the extended file specifications is being done as optional
984 settings to preserve backward compatibility with Perl scripts that
985 assume the previous VMS limitations.
986
987 In general routines on VMS that get a Unix format file specification
988 should return it in a Unix format, and when they get a VMS format
989 specification they should return a VMS format unless they are
990 documented to do a conversion.
991
992 For routines that generate return a file specification, VMS allows
993 setting if the C library which Perl is built on if it will be returned
994 in VMS format or in Unix format.
995
996 With the ODS-2 file system, there is not much difference in syntax of
997 filenames without paths for VMS or Unix. With the extended character
998 set available with ODS-5 there can be a significant difference.
999
1000 Because of this, existing Perl scripts written for VMS were sometimes
1001 treating VMS and Unix filenames interchangeably. Without the extended
1002 character set enabled, this behavior will mostly be maintained for
1003 backwards compatibility.
1004
1005 When extended characters are enabled with ODS-5, the handling of Unix
1006 formatted file specifications is to that of a Unix system.
1007
1008 VMS file specifications without extensions have a trailing dot. An
1009 equivalent Unix file specification should not show the trailing dot.
1010
1011 The result of all of this, is that for VMS, for portable scripts, you
1012 can not depend on Perl to present the filenames in lowercase, to be
1013 case sensitive, and that the filenames could be returned in either Unix
1014 or VMS format.
1015
1016 And if a routine returns a file specification, unless it is intended to
1017 convert it, it should return it in the same format as it found it.
1018
1019 "readdir" by default has traditionally returned lowercased filenames.
1020 When the ODS-5 support is enabled, it will return the exact case of the
1021 filename on the disk.
1022
1023 Files without extensions have a trailing period on them, so doing a
1024 "readdir" in the default mode with a file named A.;5 will return a.
1025 when VMS is (though that file could be opened with "open(FH, 'A')").
1026
1027 With support for extended file specifications and if "opendir" was
1028 given a Unix format directory, a file named A.;5 will return a and
1029 optionally in the exact case on the disk. When "opendir" is given a
1030 VMS format directory, then "readdir" should return a., and again with
1031 the optionally the exact case.
1032
1033 RMS had an eight level limit on directory depths from any rooted
1034 logical (allowing 16 levels overall) prior to VMS 7.2, and even with
1035 versions of VMS on VAX up through 7.3. Hence
1036 "PERL_ROOT:[LIB.2.3.4.5.6.7.8]" is a valid directory specification but
1037 "PERL_ROOT:[LIB.2.3.4.5.6.7.8.9]" is not. Makefile.PL authors might
1038 have to take this into account, but at least they can refer to the
1039 former as "/PERL_ROOT/lib/2/3/4/5/6/7/8/".
1040
1041 Pumpkings and module integrators can easily see whether files with too
1042 many directory levels have snuck into the core by running the following
1043 in the top-level source directory:
1044
1045 $ perl -ne "$_=~s/\s+.*//; print if scalar(split /\//) > 8;" < MANIFEST
1046
1047 The VMS::Filespec module, which gets installed as part of the build
1048 process on VMS, is a pure Perl module that can easily be installed on
1049 non-VMS platforms and can be helpful for conversions to and from RMS
1050 native formats. It is also now the only way that you should check to
1051 see if VMS is in a case sensitive mode.
1052
1053 What "\n" represents depends on the type of file opened. It usually
1054 represents "\012" but it could also be "\015", "\012", "\015\012",
1055 "\000", "\040", or nothing depending on the file organization and
1056 record format. The VMS::Stdio module provides access to the special
1057 fopen() requirements of files with unusual attributes on VMS.
1058
1059 TCP/IP stacks are optional on VMS, so socket routines might not be
1060 implemented. UDP sockets may not be supported.
1061
1062 The TCP/IP library support for all current versions of VMS is
1063 dynamically loaded if present, so even if the routines are configured,
1064 they may return a status indicating that they are not implemented.
1065
1066 The value of $^O on OpenVMS is "VMS". To determine the architecture
1067 that you are running on without resorting to loading all of %Config you
1068 can examine the content of the @INC array like so:
1069
1070 if (grep(/VMS_AXP/, @INC)) {
1071 print "I'm on Alpha!\n";
1072
1073 } elsif (grep(/VMS_VAX/, @INC)) {
1074 print "I'm on VAX!\n";
1075
1076 } elsif (grep(/VMS_IA64/, @INC)) {
1077 print "I'm on IA64!\n";
1078
1079 } else {
1080 print "I'm not so sure about where $^O is...\n";
1081 }
1082
1083 In general, the significant differences should only be if Perl is
1084 running on VMS_VAX or one of the 64 bit OpenVMS platforms.
1085
1086 On VMS, perl determines the UTC offset from the
1087 "SYS$TIMEZONE_DIFFERENTIAL" logical name. Although the VMS epoch began
1088 at 17-NOV-1858 00:00:00.00, calls to "localtime" are adjusted to count
1089 offsets from 01-JAN-1970 00:00:00.00, just like Unix.
1090
1091 Also see:
1092
1093 · README.vms (installed as README_vms), perlvms
1094
1095 · vmsperl list, vmsperl-subscribe@perl.org
1096
1097 · vmsperl on the web, http://www.sidhe.org/vmsperl/index.html
1098
1099 VOS
1100 Perl on VOS (also known as OpenVOS) is discussed in README.vos in the
1101 perl distribution (installed as perlvos). Perl on VOS can accept
1102 either VOS- or Unix-style file specifications as in either of the
1103 following:
1104
1105 $ perl -ne "print if /perl_setup/i" >system>notices
1106 $ perl -ne "print if /perl_setup/i" /system/notices
1107
1108 or even a mixture of both as in:
1109
1110 $ perl -ne "print if /perl_setup/i" >system/notices
1111
1112 Even though VOS allows the slash character to appear in object names,
1113 because the VOS port of Perl interprets it as a pathname delimiting
1114 character, VOS files, directories, or links whose names contain a slash
1115 character cannot be processed. Such files must be renamed before they
1116 can be processed by Perl.
1117
1118 Older releases of VOS (prior to OpenVOS Release 17.0) limit file names
1119 to 32 or fewer characters, prohibit file names from starting with a "-"
1120 character, and prohibit file names from containing any character
1121 matching "tr/ !#%&'()*;<=>?//".
1122
1123 Newer releases of VOS (OpenVOS Release 17.0 or later) support a feature
1124 known as extended names. On these releases, file names can contain up
1125 to 255 characters, are prohibited from starting with a "-" character,
1126 and the set of prohibited characters is reduced to any character
1127 matching "tr/#%*<>?//". There are restrictions involving spaces and
1128 apostrophies: these characters must not begin or end a name, nor can
1129 they immediately precede or follow a period. Additionally, a space
1130 must not immediately precede another space or hyphen. Specifically,
1131 the following character combinations are prohibited: space-space,
1132 space-hyphen, period-space, space-period, period-apostrophe,
1133 apostrophe-period, leading or trailing space, and leading or trailing
1134 apostrophe. Although an extended file name is limited to 255
1135 characters, a path name is still limited to 256 characters.
1136
1137 The value of $^O on VOS is "VOS". To determine the architecture that
1138 you are running on without resorting to loading all of %Config you can
1139 examine the content of the @INC array like so:
1140
1141 if ($^O =~ /VOS/) {
1142 print "I'm on a Stratus box!\n";
1143 } else {
1144 print "I'm not on a Stratus box!\n";
1145 die;
1146 }
1147
1148 Also see:
1149
1150 · README.vos (installed as perlvos)
1151
1152 · The VOS mailing list.
1153
1154 There is no specific mailing list for Perl on VOS. You can post
1155 comments to the comp.sys.stratus newsgroup, or use the contact
1156 information located in the distribution files on the Stratus
1157 Anonymous FTP site.
1158
1159 · VOS Perl on the web at
1160 http://ftp.stratus.com/pub/vos/posix/posix.html
1161
1162 EBCDIC Platforms
1163 Recent versions of Perl have been ported to platforms such as OS/400 on
1164 AS/400 minicomputers as well as OS/390, VM/ESA, and BS2000 for S/390
1165 Mainframes. Such computers use EBCDIC character sets internally
1166 (usually Character Code Set ID 0037 for OS/400 and either 1047 or
1167 POSIX-BC for S/390 systems). On the mainframe perl currently works
1168 under the "Unix system services for OS/390" (formerly known as
1169 OpenEdition), VM/ESA OpenEdition, or the BS200 POSIX-BC system (BS2000
1170 is supported in perl 5.6 and greater). See perlos390 for details.
1171 Note that for OS/400 there is also a port of Perl 5.8.1/5.9.0 or later
1172 to the PASE which is ASCII-based (as opposed to ILE which is EBCDIC-
1173 based), see perlos400.
1174
1175 As of R2.5 of USS for OS/390 and Version 2.3 of VM/ESA these Unix sub-
1176 systems do not support the "#!" shebang trick for script invocation.
1177 Hence, on OS/390 and VM/ESA perl scripts can be executed with a header
1178 similar to the following simple script:
1179
1180 : # use perl
1181 eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
1182 if 0;
1183 #!/usr/local/bin/perl # just a comment really
1184
1185 print "Hello from perl!\n";
1186
1187 OS/390 will support the "#!" shebang trick in release 2.8 and beyond.
1188 Calls to "system" and backticks can use POSIX shell syntax on all S/390
1189 systems.
1190
1191 On the AS/400, if PERL5 is in your library list, you may need to wrap
1192 your perl scripts in a CL procedure to invoke them like so:
1193
1194 BEGIN
1195 CALL PGM(PERL5/PERL) PARM('/QOpenSys/hello.pl')
1196 ENDPGM
1197
1198 This will invoke the perl script hello.pl in the root of the QOpenSys
1199 file system. On the AS/400 calls to "system" or backticks must use CL
1200 syntax.
1201
1202 On these platforms, bear in mind that the EBCDIC character set may have
1203 an effect on what happens with some perl functions (such as "chr",
1204 "pack", "print", "printf", "ord", "sort", "sprintf", "unpack"), as well
1205 as bit-fiddling with ASCII constants using operators like "^", "&" and
1206 "|", not to mention dealing with socket interfaces to ASCII computers
1207 (see "Newlines").
1208
1209 Fortunately, most web servers for the mainframe will correctly
1210 translate the "\n" in the following statement to its ASCII equivalent
1211 ("\r" is the same under both Unix and OS/390 & VM/ESA):
1212
1213 print "Content-type: text/html\r\n\r\n";
1214
1215 The values of $^O on some of these platforms includes:
1216
1217 uname $^O $Config{'archname'}
1218 --------------------------------------------
1219 OS/390 os390 os390
1220 OS400 os400 os400
1221 POSIX-BC posix-bc BS2000-posix-bc
1222 VM/ESA vmesa vmesa
1223
1224 Some simple tricks for determining if you are running on an EBCDIC
1225 platform could include any of the following (perhaps all):
1226
1227 if ("\t" eq "\05") { print "EBCDIC may be spoken here!\n"; }
1228
1229 if (ord('A') == 193) { print "EBCDIC may be spoken here!\n"; }
1230
1231 if (chr(169) eq 'z') { print "EBCDIC may be spoken here!\n"; }
1232
1233 One thing you may not want to rely on is the EBCDIC encoding of
1234 punctuation characters since these may differ from code page to code
1235 page (and once your module or script is rumoured to work with EBCDIC,
1236 folks will want it to work with all EBCDIC character sets).
1237
1238 Also see:
1239
1240 · perlos390, README.os390, perlbs2000, README.vmesa, perlebcdic.
1241
1242 · The perl-mvs@perl.org list is for discussion of porting issues as
1243 well as general usage issues for all EBCDIC Perls. Send a message
1244 body of "subscribe perl-mvs" to majordomo@perl.org.
1245
1246 · AS/400 Perl information at http://as400.rochester.ibm.com/ as well
1247 as on CPAN in the ports/ directory.
1248
1249 Acorn RISC OS
1250 Because Acorns use ASCII with newlines ("\n") in text files as "\012"
1251 like Unix, and because Unix filename emulation is turned on by default,
1252 most simple scripts will probably work "out of the box". The native
1253 filesystem is modular, and individual filesystems are free to be case-
1254 sensitive or insensitive, and are usually case-preserving. Some native
1255 filesystems have name length limits, which file and directory names are
1256 silently truncated to fit. Scripts should be aware that the standard
1257 filesystem currently has a name length limit of 10 characters, with up
1258 to 77 items in a directory, but other filesystems may not impose such
1259 limitations.
1260
1261 Native filenames are of the form
1262
1263 Filesystem#Special_Field::DiskName.$.Directory.Directory.File
1264
1265 where
1266
1267 Special_Field is not usually present, but may contain . and $ .
1268 Filesystem =~ m|[A-Za-z0-9_]|
1269 DsicName =~ m|[A-Za-z0-9_/]|
1270 $ represents the root directory
1271 . is the path separator
1272 @ is the current directory (per filesystem but machine global)
1273 ^ is the parent directory
1274 Directory and File =~ m|[^\0- "\.\$\%\&:\@\\^\|\177]+|
1275
1276 The default filename translation is roughly "tr|/.|./|;"
1277
1278 Note that ""ADFS::HardDisk.$.File" ne 'ADFS::HardDisk.$.File'" and that
1279 the second stage of "$" interpolation in regular expressions will fall
1280 foul of the $. if scripts are not careful.
1281
1282 Logical paths specified by system variables containing comma-separated
1283 search lists are also allowed; hence "System:Modules" is a valid
1284 filename, and the filesystem will prefix "Modules" with each section of
1285 "System$Path" until a name is made that points to an object on disk.
1286 Writing to a new file "System:Modules" would be allowed only if
1287 "System$Path" contains a single item list. The filesystem will also
1288 expand system variables in filenames if enclosed in angle brackets, so
1289 "<System$Dir>.Modules" would look for the file
1290 "$ENV{'System$Dir'} . 'Modules'". The obvious implication of this is
1291 that fully qualified filenames can start with "<>" and should be
1292 protected when "open" is used for input.
1293
1294 Because "." was in use as a directory separator and filenames could not
1295 be assumed to be unique after 10 characters, Acorn implemented the C
1296 compiler to strip the trailing ".c" ".h" ".s" and ".o" suffix from
1297 filenames specified in source code and store the respective files in
1298 subdirectories named after the suffix. Hence files are translated:
1299
1300 foo.h h.foo
1301 C:foo.h C:h.foo (logical path variable)
1302 sys/os.h sys.h.os (C compiler groks Unix-speak)
1303 10charname.c c.10charname
1304 10charname.o o.10charname
1305 11charname_.c c.11charname (assuming filesystem truncates at 10)
1306
1307 The Unix emulation library's translation of filenames to native assumes
1308 that this sort of translation is required, and it allows a user-defined
1309 list of known suffixes that it will transpose in this fashion. This
1310 may seem transparent, but consider that with these rules
1311 "foo/bar/baz.h" and "foo/bar/h/baz" both map to "foo.bar.h.baz", and
1312 that "readdir" and "glob" cannot and do not attempt to emulate the
1313 reverse mapping. Other "."'s in filenames are translated to "/".
1314
1315 As implied above, the environment accessed through %ENV is global, and
1316 the convention is that program specific environment variables are of
1317 the form "Program$Name". Each filesystem maintains a current
1318 directory, and the current filesystem's current directory is the global
1319 current directory. Consequently, sociable programs don't change the
1320 current directory but rely on full pathnames, and programs (and
1321 Makefiles) cannot assume that they can spawn a child process which can
1322 change the current directory without affecting its parent (and everyone
1323 else for that matter).
1324
1325 Because native operating system filehandles are global and are
1326 currently allocated down from 255, with 0 being a reserved value, the
1327 Unix emulation library emulates Unix filehandles. Consequently, you
1328 can't rely on passing "STDIN", "STDOUT", or "STDERR" to your children.
1329
1330 The desire of users to express filenames of the form "<Foo$Dir>.Bar" on
1331 the command line unquoted causes problems, too: "``" command output
1332 capture has to perform a guessing game. It assumes that a string
1333 "<[^<>]+\$[^<>]>" is a reference to an environment variable, whereas
1334 anything else involving "<" or ">" is redirection, and generally
1335 manages to be 99% right. Of course, the problem remains that scripts
1336 cannot rely on any Unix tools being available, or that any tools found
1337 have Unix-like command line arguments.
1338
1339 Extensions and XS are, in theory, buildable by anyone using free tools.
1340 In practice, many don't, as users of the Acorn platform are used to
1341 binary distributions. MakeMaker does run, but no available make
1342 currently copes with MakeMaker's makefiles; even if and when this
1343 should be fixed, the lack of a Unix-like shell will cause problems with
1344 makefile rules, especially lines of the form "cd sdbm && make all", and
1345 anything using quoting.
1346
1347 "RISC OS" is the proper name for the operating system, but the value in
1348 $^O is "riscos" (because we don't like shouting).
1349
1350 Other perls
1351 Perl has been ported to many platforms that do not fit into any of the
1352 categories listed above. Some, such as AmigaOS, BeOS, HP MPE/iX, QNX,
1353 Plan 9, and VOS, have been well-integrated into the standard Perl
1354 source code kit. You may need to see the ports/ directory on CPAN for
1355 information, and possibly binaries, for the likes of: aos, Atari ST,
1356 lynxos, riscos, Novell Netware, Tandem Guardian, etc. (Yes, we know
1357 that some of these OSes may fall under the Unix category, but we are
1358 not a standards body.)
1359
1360 Some approximate operating system names and their $^O values in the
1361 "OTHER" category include:
1362
1363 OS $^O $Config{'archname'}
1364 ------------------------------------------
1365 Amiga DOS amigaos m68k-amigos
1366 BeOS beos
1367 MPE/iX mpeix PA-RISC1.1
1368
1369 See also:
1370
1371 · Amiga, README.amiga (installed as perlamiga).
1372
1373 · Be OS, README.beos
1374
1375 · HP 300 MPE/iX, README.mpeix and Mark Bixby's web page
1376 http://www.bixby.org/mark/porting.html
1377
1378 · A free perl5-based PERL.NLM for Novell Netware is available in
1379 precompiled binary and source code form from http://www.novell.com/
1380 as well as from CPAN.
1381
1382 · Plan 9, README.plan9
1383
1385 Listed below are functions that are either completely unimplemented or
1386 else have been implemented differently on various platforms. Following
1387 each description will be, in parentheses, a list of platforms that the
1388 description applies to.
1389
1390 The list may well be incomplete, or even wrong in some places. When in
1391 doubt, consult the platform-specific README files in the Perl source
1392 distribution, and any other documentation resources accompanying a
1393 given port.
1394
1395 Be aware, moreover, that even among Unix-ish systems there are
1396 variations.
1397
1398 For many functions, you can also query %Config, exported by default
1399 from the Config module. For example, to check whether the platform has
1400 the "lstat" call, check $Config{d_lstat}. See Config for a full
1401 description of available variables.
1402
1403 Alphabetical Listing of Perl Functions
1404 -X "-w" only inspects the read-only file attribute
1405 (FILE_ATTRIBUTE_READONLY), which determines whether the
1406 directory can be deleted, not whether it can be written to.
1407 Directories always have read and write access unless denied by
1408 discretionary access control lists (DACLs). (Win32)
1409
1410 "-r", "-w", "-x", and "-o" tell whether the file is accessible,
1411 which may not reflect UIC-based file protections. (VMS)
1412
1413 "-s" by name on an open file will return the space reserved on
1414 disk, rather than the current extent. "-s" on an open
1415 filehandle returns the current size. (RISC OS)
1416
1417 "-R", "-W", "-X", "-O" are indistinguishable from "-r", "-w",
1418 "-x", "-o". (Win32, VMS, RISC OS)
1419
1420 "-g", "-k", "-l", "-u", "-A" are not particularly meaningful.
1421 (Win32, VMS, RISC OS)
1422
1423 "-p" is not particularly meaningful. (VMS, RISC OS)
1424
1425 "-d" is true if passed a device spec without an explicit
1426 directory. (VMS)
1427
1428 "-x" (or "-X") determine if a file ends in one of the
1429 executable suffixes. "-S" is meaningless. (Win32)
1430
1431 "-x" (or "-X") determine if a file has an executable file type.
1432 (RISC OS)
1433
1434 alarm Emulated using timers that must be explicitly polled whenever
1435 Perl wants to dispatch "safe signals" and therefore cannot
1436 interrupt blocking system calls. (Win32)
1437
1438 atan2 Due to issues with various CPUs, math libraries, compilers, and
1439 standards, results for "atan2()" may vary depending on any
1440 combination of the above. Perl attempts to conform to the Open
1441 Group/IEEE standards for the results returned from "atan2()",
1442 but cannot force the issue if the system Perl is run on does
1443 not allow it. (Tru64, HP-UX 10.20)
1444
1445 The current version of the standards for "atan2()" is available
1446 at
1447 <http://www.opengroup.org/onlinepubs/009695399/functions/atan2.html>.
1448
1449 binmode Meaningless. (RISC OS)
1450
1451 Reopens file and restores pointer; if function fails,
1452 underlying filehandle may be closed, or pointer may be in a
1453 different position. (VMS)
1454
1455 The value returned by "tell" may be affected after the call,
1456 and the filehandle may be flushed. (Win32)
1457
1458 chmod Only good for changing "owner" read-write access, "group", and
1459 "other" bits are meaningless. (Win32)
1460
1461 Only good for changing "owner" and "other" read-write access.
1462 (RISC OS)
1463
1464 Access permissions are mapped onto VOS access-control list
1465 changes. (VOS)
1466
1467 The actual permissions set depend on the value of the "CYGWIN"
1468 in the SYSTEM environment settings. (Cygwin)
1469
1470 chown Not implemented. (Win32, Plan 9, RISC OS)
1471
1472 Does nothing, but won't fail. (Win32)
1473
1474 A little funky, because VOS's notion of ownership is a little
1475 funky (VOS).
1476
1477 chroot Not implemented. (Win32, VMS, Plan 9, RISC OS, VOS, VM/ESA)
1478
1479 crypt May not be available if library or source was not provided when
1480 building perl. (Win32)
1481
1482 dbmclose
1483 Not implemented. (VMS, Plan 9, VOS)
1484
1485 dbmopen Not implemented. (VMS, Plan 9, VOS)
1486
1487 dump Not useful. (RISC OS)
1488
1489 Not supported. (Cygwin, Win32)
1490
1491 Invokes VMS debugger. (VMS)
1492
1493 exec Implemented via Spawn. (VM/ESA)
1494
1495 Does not automatically flush output handles on some platforms.
1496 (SunOS, Solaris, HP-UX)
1497
1498 exit Emulates Unix exit() (which considers "exit 1" to indicate an
1499 error) by mapping the 1 to SS$_ABORT (44). This behavior may
1500 be overridden with the pragma "use vmsish 'exit'". As with the
1501 CRTL's exit() function, "exit 0" is also mapped to an exit
1502 status of SS$_NORMAL (1); this mapping cannot be overridden.
1503 Any other argument to exit() is used directly as Perl's exit
1504 status. On VMS, unless the future POSIX_EXIT mode is enabled,
1505 the exit code should always be a valid VMS exit code and not a
1506 generic number. When the POSIX_EXIT mode is enabled, a generic
1507 number will be encoded in a method compatible with the C
1508 library _POSIX_EXIT macro so that it can be decoded by other
1509 programs, particularly ones written in C, like the GNV package.
1510 (VMS)
1511
1512 fcntl Not implemented. (Win32) Some functions available based on the
1513 version of VMS. (VMS)
1514
1515 flock Not implemented (VMS, RISC OS, VOS).
1516
1517 Available only on Windows NT (not on Windows 95). (Win32)
1518
1519 fork Not implemented. (AmigaOS, RISC OS, VM/ESA, VMS)
1520
1521 Emulated using multiple interpreters. See perlfork. (Win32)
1522
1523 Does not automatically flush output handles on some platforms.
1524 (SunOS, Solaris, HP-UX)
1525
1526 getlogin
1527 Not implemented. (RISC OS)
1528
1529 getpgrp Not implemented. (Win32, VMS, RISC OS)
1530
1531 getppid Not implemented. (Win32, RISC OS)
1532
1533 getpriority
1534 Not implemented. (Win32, VMS, RISC OS, VOS, VM/ESA)
1535
1536 getpwnam
1537 Not implemented. (Win32)
1538
1539 Not useful. (RISC OS)
1540
1541 getgrnam
1542 Not implemented. (Win32, VMS, RISC OS)
1543
1544 getnetbyname
1545 Not implemented. (Win32, Plan 9)
1546
1547 getpwuid
1548 Not implemented. (Win32)
1549
1550 Not useful. (RISC OS)
1551
1552 getgrgid
1553 Not implemented. (Win32, VMS, RISC OS)
1554
1555 getnetbyaddr
1556 Not implemented. (Win32, Plan 9)
1557
1558 getprotobynumber
1559 getservbyport
1560 getpwent
1561 Not implemented. (Win32, VM/ESA)
1562
1563 getgrent
1564 Not implemented. (Win32, VMS, VM/ESA)
1565
1566 gethostbyname
1567 "gethostbyname('localhost')" does not work everywhere: you may
1568 have to use "gethostbyname('127.0.0.1')". (Irix 5)
1569
1570 gethostent
1571 Not implemented. (Win32)
1572
1573 getnetent
1574 Not implemented. (Win32, Plan 9)
1575
1576 getprotoent
1577 Not implemented. (Win32, Plan 9)
1578
1579 getservent
1580 Not implemented. (Win32, Plan 9)
1581
1582 sethostent
1583 Not implemented. (Win32, Plan 9, RISC OS)
1584
1585 setnetent
1586 Not implemented. (Win32, Plan 9, RISC OS)
1587
1588 setprotoent
1589 Not implemented. (Win32, Plan 9, RISC OS)
1590
1591 setservent
1592 Not implemented. (Plan 9, Win32, RISC OS)
1593
1594 endpwent
1595 Not implemented. (MPE/iX, VM/ESA, Win32)
1596
1597 endgrent
1598 Not implemented. (MPE/iX, RISC OS, VM/ESA, VMS, Win32)
1599
1600 endhostent
1601 Not implemented. (Win32)
1602
1603 endnetent
1604 Not implemented. (Win32, Plan 9)
1605
1606 endprotoent
1607 Not implemented. (Win32, Plan 9)
1608
1609 endservent
1610 Not implemented. (Plan 9, Win32)
1611
1612 getsockopt SOCKET,LEVEL,OPTNAME
1613 Not implemented. (Plan 9)
1614
1615 glob This operator is implemented via the File::Glob extension on
1616 most platforms. See File::Glob for portability information.
1617
1618 gmtime In theory, gmtime() is reliable from -2**63 to 2**63-1.
1619 However, because work arounds in the implementation use
1620 floating point numbers, it will become inaccurate as the time
1621 gets larger. This is a bug and will be fixed in the future.
1622
1623 On VOS, time values are 32-bit quantities.
1624
1625 ioctl FILEHANDLE,FUNCTION,SCALAR
1626 Not implemented. (VMS)
1627
1628 Available only for socket handles, and it does what the
1629 ioctlsocket() call in the Winsock API does. (Win32)
1630
1631 Available only for socket handles. (RISC OS)
1632
1633 kill Not implemented, hence not useful for taint checking. (RISC OS)
1634
1635 "kill()" doesn't have the semantics of "raise()", i.e. it
1636 doesn't send a signal to the identified process like it does on
1637 Unix platforms. Instead "kill($sig, $pid)" terminates the
1638 process identified by $pid, and makes it exit immediately with
1639 exit status $sig. As in Unix, if $sig is 0 and the specified
1640 process exists, it returns true without actually terminating
1641 it. (Win32)
1642
1643 "kill(-9, $pid)" will terminate the process specified by $pid
1644 and recursively all child processes owned by it. This is
1645 different from the Unix semantics, where the signal will be
1646 delivered to all processes in the same process group as the
1647 process specified by $pid. (Win32)
1648
1649 Is not supported for process identification number of 0 or
1650 negative numbers. (VMS)
1651
1652 link Not implemented. (MPE/iX, RISC OS, VOS)
1653
1654 Link count not updated because hard links are not quite that
1655 hard (They are sort of half-way between hard and soft links).
1656 (AmigaOS)
1657
1658 Hard links are implemented on Win32 under NTFS only. They are
1659 natively supported on Windows 2000 and later. On Windows NT
1660 they are implemented using the Windows POSIX subsystem support
1661 and the Perl process will need Administrator or Backup Operator
1662 privileges to create hard links.
1663
1664 Available on 64 bit OpenVMS 8.2 and later. (VMS)
1665
1666 localtime
1667 localtime() has the same range as gmtime, but because time zone
1668 rules change its accuracy for historical and future times may
1669 degrade but usually by no more than an hour.
1670
1671 lstat Not implemented. (RISC OS)
1672
1673 Return values (especially for device and inode) may be bogus.
1674 (Win32)
1675
1676 msgctl
1677 msgget
1678 msgsnd
1679 msgrcv Not implemented. (Win32, VMS, Plan 9, RISC OS, VOS)
1680
1681 open open to "|-" and "-|" are unsupported. (Win32, RISC OS)
1682
1683 Opening a process does not automatically flush output handles
1684 on some platforms. (SunOS, Solaris, HP-UX)
1685
1686 readlink
1687 Not implemented. (Win32, VMS, RISC OS)
1688
1689 rename Can't move directories between directories on different logical
1690 volumes. (Win32)
1691
1692 select Only implemented on sockets. (Win32, VMS)
1693
1694 Only reliable on sockets. (RISC OS)
1695
1696 Note that the "select FILEHANDLE" form is generally portable.
1697
1698 semctl
1699 semget
1700 semop Not implemented. (Win32, VMS, RISC OS)
1701
1702 setgrent
1703 Not implemented. (MPE/iX, VMS, Win32, RISC OS)
1704
1705 setpgrp Not implemented. (Win32, VMS, RISC OS, VOS)
1706
1707 setpriority
1708 Not implemented. (Win32, VMS, RISC OS, VOS)
1709
1710 setpwent
1711 Not implemented. (MPE/iX, Win32, RISC OS)
1712
1713 setsockopt
1714 Not implemented. (Plan 9)
1715
1716 shmctl
1717 shmget
1718 shmread
1719 shmwrite
1720 Not implemented. (Win32, VMS, RISC OS, VOS)
1721
1722 sockatmark
1723 A relatively recent addition to socket functions, may not be
1724 implemented even in Unix platforms.
1725
1726 socketpair
1727 Not implemented. (RISC OS, VM/ESA)
1728
1729 Available on OpenVOS Release 17.0 or later. (VOS)
1730
1731 Available on 64 bit OpenVMS 8.2 and later. (VMS)
1732
1733 stat Platforms that do not have rdev, blksize, or blocks will return
1734 these as '', so numeric comparison or manipulation of these
1735 fields may cause 'not numeric' warnings.
1736
1737 ctime not supported on UFS (Mac OS X).
1738
1739 ctime is creation time instead of inode change time (Win32).
1740
1741 device and inode are not meaningful. (Win32)
1742
1743 device and inode are not necessarily reliable. (VMS)
1744
1745 mtime, atime and ctime all return the last modification time.
1746 Device and inode are not necessarily reliable. (RISC OS)
1747
1748 dev, rdev, blksize, and blocks are not available. inode is not
1749 meaningful and will differ between stat calls on the same file.
1750 (os2)
1751
1752 some versions of cygwin when doing a stat("foo") and if not
1753 finding it may then attempt to stat("foo.exe") (Cygwin)
1754
1755 On Win32 stat() needs to open the file to determine the link
1756 count and update attributes that may have been changed through
1757 hard links. Setting ${^WIN32_SLOPPY_STAT} to a true value
1758 speeds up stat() by not performing this operation. (Win32)
1759
1760 symlink Not implemented. (Win32, RISC OS)
1761
1762 Implemented on 64 bit VMS 8.3. VMS requires the symbolic link
1763 to be in Unix syntax if it is intended to resolve to a valid
1764 path.
1765
1766 syscall Not implemented. (Win32, VMS, RISC OS, VOS, VM/ESA)
1767
1768 sysopen The traditional "0", "1", and "2" MODEs are implemented with
1769 different numeric values on some systems. The flags exported
1770 by "Fcntl" (O_RDONLY, O_WRONLY, O_RDWR) should work everywhere
1771 though. (Mac OS, OS/390, VM/ESA)
1772
1773 system As an optimization, may not call the command shell specified in
1774 $ENV{PERL5SHELL}. "system(1, @args)" spawns an external
1775 process and immediately returns its process designator, without
1776 waiting for it to terminate. Return value may be used
1777 subsequently in "wait" or "waitpid". Failure to spawn() a
1778 subprocess is indicated by setting $? to "255 << 8". $? is set
1779 in a way compatible with Unix (i.e. the exitstatus of the
1780 subprocess is obtained by "$? >> 8", as described in the
1781 documentation). (Win32)
1782
1783 There is no shell to process metacharacters, and the native
1784 standard is to pass a command line terminated by "\n" "\r" or
1785 "\0" to the spawned program. Redirection such as "> foo" is
1786 performed (if at all) by the run time library of the spawned
1787 program. "system" list will call the Unix emulation library's
1788 "exec" emulation, which attempts to provide emulation of the
1789 stdin, stdout, stderr in force in the parent, providing the
1790 child program uses a compatible version of the emulation
1791 library. scalar will call the native command line direct and
1792 no such emulation of a child Unix program will exists. Mileage
1793 will vary. (RISC OS)
1794
1795 Does not automatically flush output handles on some platforms.
1796 (SunOS, Solaris, HP-UX)
1797
1798 The return value is POSIX-like (shifted up by 8 bits), which
1799 only allows room for a made-up value derived from the severity
1800 bits of the native 32-bit condition code (unless overridden by
1801 "use vmsish 'status'"). If the native condition code is one
1802 that has a POSIX value encoded, the POSIX value will be decoded
1803 to extract the expected exit value. For more details see "$?"
1804 in perlvms. (VMS)
1805
1806 times "cumulative" times will be bogus. On anything other than
1807 Windows NT or Windows 2000, "system" time will be bogus, and
1808 "user" time is actually the time returned by the clock()
1809 function in the C runtime library. (Win32)
1810
1811 Not useful. (RISC OS)
1812
1813 truncate
1814 Not implemented. (Older versions of VMS)
1815
1816 Truncation to same-or-shorter lengths only. (VOS)
1817
1818 If a FILEHANDLE is supplied, it must be writable and opened in
1819 append mode (i.e., use "open(FH, '>>filename')" or
1820 "sysopen(FH,...,O_APPEND|O_RDWR)". If a filename is supplied,
1821 it should not be held open elsewhere. (Win32)
1822
1823 umask Returns undef where unavailable, as of version 5.005.
1824
1825 "umask" works but the correct permissions are set only when the
1826 file is finally closed. (AmigaOS)
1827
1828 utime Only the modification time is updated. (BeOS, VMS, RISC OS)
1829
1830 May not behave as expected. Behavior depends on the C runtime
1831 library's implementation of utime(), and the filesystem being
1832 used. The FAT filesystem typically does not support an "access
1833 time" field, and it may limit timestamps to a granularity of
1834 two seconds. (Win32)
1835
1836 wait
1837 waitpid Can only be applied to process handles returned for processes
1838 spawned using "system(1, ...)" or pseudo processes created with
1839 "fork()". (Win32)
1840
1841 Not useful. (RISC OS)
1842
1844 The following platforms are known to build Perl 5.12 (as of April 2010,
1845 its release date) from the standard source code distribution available
1846 at http://www.cpan.org/src
1847
1848 Linux (x86, ARM, IA64)
1849 HP-UX
1850 AIX
1851 Win32
1852 Windows 2000
1853 Windows XP
1854 Windows Server 2003
1855 Windows Vista
1856 Windows Server 2008
1857 Windows 7
1858 Cygwin
1859 Solaris (x86, SPARC)
1860 OpenVMS
1861 Alpha (7.2 and later)
1862 I64 (8.2 and later)
1863 Symbian
1864 NetBSD
1865 FreeBSD
1866 Haiku
1867 Irix (6.5. What else?)
1868 OpenBSD
1869 Dragonfly BSD
1870 MirOS BSD
1871 Caveats:
1872
1873 time_t issues that may or may not be fixed
1874 Symbian (Series 60 v3, 3.2 and 5 - what else?)
1875 Stratus VOS / OpenVOS
1876 AIX
1877
1879 The following platforms were supported by a previous version of Perl
1880 but have been officially removed from Perl's source code as of 5.12:
1881
1882 Atari MiNT
1883 Apollo Domain/OS
1884 Apple Mac OS 8/9
1885 Tenon Machten
1886
1887 The following platforms may still work as of Perl 5.12, but Perl's
1888 developers have made an explicit decision to discontinue support for
1889 them:
1890
1891 Windows 95
1892 Windows 98
1893 Windows ME
1894 Windows NT4
1895
1897 As of July 2002 (the Perl release 5.8.0), the following platforms were
1898 able to build Perl from the standard source code distribution available
1899 at http://www.cpan.org/src/
1900
1901 AIX
1902 BeOS
1903 BSD/OS (BSDi)
1904 Cygwin
1905 DG/UX
1906 DOS DJGPP 1)
1907 DYNIX/ptx
1908 EPOC R5
1909 FreeBSD
1910 HI-UXMPP (Hitachi) (5.8.0 worked but we didn't know it)
1911 HP-UX
1912 IRIX
1913 Linux
1914 Mac OS Classic
1915 Mac OS X (Darwin)
1916 MPE/iX
1917 NetBSD
1918 NetWare
1919 NonStop-UX
1920 ReliantUNIX (formerly SINIX)
1921 OpenBSD
1922 OpenVMS (formerly VMS)
1923 Open UNIX (Unixware) (since Perl 5.8.1/5.9.0)
1924 OS/2
1925 OS/400 (using the PASE) (since Perl 5.8.1/5.9.0)
1926 PowerUX
1927 POSIX-BC (formerly BS2000)
1928 QNX
1929 Solaris
1930 SunOS 4
1931 SUPER-UX (NEC)
1932 Tru64 UNIX (formerly DEC OSF/1, Digital UNIX)
1933 UNICOS
1934 UNICOS/mk
1935 UTS
1936 VOS
1937 Win95/98/ME/2K/XP 2)
1938 WinCE
1939 z/OS (formerly OS/390)
1940 VM/ESA
1941
1942 1) in DOS mode either the DOS or OS/2 ports can be used
1943 2) compilers: Borland, MinGW (GCC), VC6
1944
1945 The following platforms worked with the previous releases (5.6 and
1946 5.7), but we did not manage either to fix or to test these in time for
1947 the 5.8.0 release. There is a very good chance that many of these will
1948 work fine with the 5.8.0.
1949
1950 BSD/OS
1951 DomainOS
1952 Hurd
1953 LynxOS
1954 MachTen
1955 PowerMAX
1956 SCO SV
1957 SVR4
1958 Unixware
1959 Windows 3.1
1960
1961 Known to be broken for 5.8.0 (but 5.6.1 and 5.7.2 can be used):
1962
1963 AmigaOS
1964
1965 The following platforms have been known to build Perl from source in
1966 the past (5.005_03 and earlier), but we haven't been able to verify
1967 their status for the current release, either because the
1968 hardware/software platforms are rare or because we don't have an active
1969 champion on these platforms--or both. They used to work, though, so go
1970 ahead and try compiling them, and let perlbug@perl.org of any trouble.
1971
1972 3b1
1973 A/UX
1974 ConvexOS
1975 CX/UX
1976 DC/OSx
1977 DDE SMES
1978 DOS EMX
1979 Dynix
1980 EP/IX
1981 ESIX
1982 FPS
1983 GENIX
1984 Greenhills
1985 ISC
1986 MachTen 68k
1987 MPC
1988 NEWS-OS
1989 NextSTEP
1990 OpenSTEP
1991 Opus
1992 Plan 9
1993 RISC/os
1994 SCO ODT/OSR
1995 Stellar
1996 SVR2
1997 TI1500
1998 TitanOS
1999 Ultrix
2000 Unisys Dynix
2001
2002 The following platforms have their own source code distributions and
2003 binaries available via http://www.cpan.org/ports/
2004
2005 Perl release
2006
2007 OS/400 (ILE) 5.005_02
2008 Tandem Guardian 5.004
2009
2010 The following platforms have only binaries available via
2011 http://www.cpan.org/ports/index.html :
2012
2013 Perl release
2014
2015 Acorn RISCOS 5.005_02
2016 AOS 5.002
2017 LynxOS 5.004_02
2018
2019 Although we do suggest that you always build your own Perl from the
2020 source code, both for maximal configurability and for security, in case
2021 you are in a hurry you can check http://www.cpan.org/ports/index.html
2022 for binary distributions.
2023
2025 perlaix, perlamiga, perlapollo, perlbeos, perlbs2000, perlce,
2026 perlcygwin, perldgux, perldos, perlepoc, perlebcdic, perlfreebsd,
2027 perlhurd, perlhpux, perlirix, perlmacos, perlmacosx, perlmpeix,
2028 perlnetware, perlos2, perlos390, perlos400, perlplan9, perlqnx,
2029 perlsolaris, perltru64, perlunicode, perlvmesa, perlvms, perlvos,
2030 perlwin32, and Win32.
2031
2033 Abigail <abigail@foad.org>, Charles Bailey <bailey@newman.upenn.edu>,
2034 Graham Barr <gbarr@pobox.com>, Tom Christiansen <tchrist@perl.com>,
2035 Nicholas Clark <nick@ccl4.org>, Thomas Dorner <Thomas.Dorner@start.de>,
2036 Andy Dougherty <doughera@lafayette.edu>, Dominic Dunlop
2037 <domo@computer.org>, Neale Ferguson <neale@vma.tabnsw.com.au>, David J.
2038 Fiander <davidf@mks.com>, Paul Green <Paul.Green@stratus.com>, M.J.T.
2039 Guy <mjtg@cam.ac.uk>, Jarkko Hietaniemi <jhi@iki.fi>, Luther Huffman
2040 <lutherh@stratcom.com>, Nick Ing-Simmons <nick@ing-simmons.net>,
2041 Andreas J. Koenig <a.koenig@mind.de>, Markus Laker
2042 <mlaker@contax.co.uk>, Andrew M. Langmead <aml@world.std.com>, Larry
2043 Moore <ljmoore@freespace.net>, Paul Moore
2044 <Paul.Moore@uk.origin-it.com>, Chris Nandor <pudge@pobox.com>, Matthias
2045 Neeracher <neeracher@mac.com>, Philip Newton <pne@cpan.org>, Gary Ng
2046 <71564.1743@CompuServe.COM>, Tom Phoenix <rootbeer@teleport.com>, Andre
2047 Pirard <A.Pirard@ulg.ac.be>, Peter Prymmer <pvhp@forte.com>, Hugo van
2048 der Sanden <hv@crypt0.demon.co.uk>, Gurusamy Sarathy
2049 <gsar@activestate.com>, Paul J. Schinder <schinder@pobox.com>, Michael
2050 G Schwern <schwern@pobox.com>, Dan Sugalski <dan@sidhe.org>, Nathan
2051 Torkington <gnat@frii.com>. John Malmberg <wb8tyw@qsl.net>
2052
2053
2054
2055perl v5.12.4 2011-06-07 PERLPORT(1)