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