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