assorted tweaks
[p5sagit/p5-mst-13.2.git] / pod / perlport.pod
CommitLineData
e41182b5 1=head1 NAME
2
3perlport - Writing portable Perl
4
5
6=head1 DESCRIPTION
7
8Perl runs on a variety of operating systems. While most of them share
9a lot in common, they also have their own very particular and unique
10features.
11
12This document is meant to help you to find out what constitutes portable
0a47030a 13Perl code, so that once you have made your decision to write portably,
e41182b5 14you know where the lines are drawn, and you can stay within them.
15
6ab3f9cb 16There is a tradeoff between taking full advantage of one particular type
17of computer, and taking advantage of a full range of them. Naturally,
0a47030a 18as you make your range bigger (and thus more diverse), the common
19denominators drop, and you are left with fewer areas of common ground in
20which you can operate to accomplish a particular task. Thus, when you
21begin attacking a problem, it is important to consider which part of the
22tradeoff curve you want to operate under. Specifically, whether it is
23important to you that the task that you are coding needs the full
24generality of being portable, or if it is sufficient to just get the job
25done. This is the hardest choice to be made. The rest is easy, because
26Perl provides lots of choices, whichever way you want to approach your
27problem.
28
29Looking at it another way, writing portable code is usually about
30willfully limiting your available choices. Naturally, it takes discipline
31to do that.
e41182b5 32
33Be aware of two important points:
34
6ab3f9cb 35
e41182b5 36=over 4
37
38=item Not all Perl programs have to be portable
39
40There is no reason why you should not use Perl as a language to glue Unix
41tools together, or to prototype a Macintosh application, or to manage the
42Windows registry. If it makes no sense to aim for portability for one
43reason or another in a given program, then don't bother.
44
6ab3f9cb 45=item The vast majority of Perl I<is> portable
e41182b5 46
47Don't be fooled into thinking that it is hard to create portable Perl
48code. It isn't. Perl tries its level-best to bridge the gaps between
49what's available on different platforms, and all the means available to
50use those features. Thus almost all Perl code runs on any machine
6ab3f9cb 51without modification. But there are some significant issues in
e41182b5 52writing portable code, and this document is entirely about those issues.
53
54=back
55
6ab3f9cb 56
e41182b5 57Here's the general rule: When you approach a task that is commonly done
58using a whole range of platforms, think in terms of writing portable
59code. That way, you don't sacrifice much by way of the implementation
60choices you can avail yourself of, and at the same time you can give
61your users lots of platform choices. On the other hand, when you have to
62take advantage of some unique feature of a particular platform, as is
63often the case with systems programming (whether for Unix, Windows,
64S<Mac OS>, VMS, etc.), consider writing platform-specific code.
65
0a47030a 66When the code will run on only two or three operating systems, then you
67may only need to consider the differences of those particular systems.
68The important thing is to decide where the code will run, and to be
69deliberate in your decision.
70
71The material below is separated into three main sections: main issues of
72portability (L<"ISSUES">, platform-specific issues (L<"PLATFORMS">, and
73builtin perl functions that behave differently on various ports
74(L<"FUNCTION IMPLEMENTATIONS">.
e41182b5 75
76This information should not be considered complete; it includes possibly
b8099c3d 77transient information about idiosyncrasies of some of the ports, almost
e41182b5 78all of which are in a state of constant evolution. Thus this material
79should be considered a perpetual work in progress
80(E<lt>IMG SRC="yellow_sign.gif" ALT="Under Construction"E<gt>).
81
82
83=head1 ISSUES
84
85=head2 Newlines
86
638bc118 87In most operating systems, lines in files are terminated by newlines.
e41182b5 88Just what is used as a newline may vary from OS to OS. Unix
89traditionally uses C<\012>, one kind of Windows I/O uses C<\015\012>,
90and S<Mac OS> uses C<\015>.
91
92Perl uses C<\n> to represent the "logical" newline, where what
93is logical may depend on the platform in use. In MacPerl, C<\n>
94always means C<\015>. In DOSish perls, C<\n> usually means C<\012>, but
95when accessing a file in "text" mode, STDIO translates it to (or from)
6ab3f9cb 96C<\015\012>. C<\015\012> is commonly referred to as CRLF.
e41182b5 97
98Due to the "text" mode translation, DOSish perls have limitations
99of using C<seek> and C<tell> when a file is being accessed in "text"
100mode. Specifically, if you stick to C<seek>-ing to locations you got
101from C<tell> (and no others), you are usually free to use C<seek> and
102C<tell> even in "text" mode. In general, using C<seek> or C<tell> or
103other file operations that count bytes instead of characters, without
104considering the length of C<\n>, may be non-portable. If you use
105C<binmode> on a file, however, you can usually use C<seek> and C<tell>
106with arbitrary values quite safely.
107
108A common misconception in socket programming is that C<\n> eq C<\012>
0a47030a 109everywhere. When using protocols such as common Internet protocols,
e41182b5 110C<\012> and C<\015> are called for specifically, and the values of
111the logical C<\n> and C<\r> (carriage return) are not reliable.
112
113 print SOCKET "Hi there, client!\r\n"; # WRONG
114 print SOCKET "Hi there, client!\015\012"; # RIGHT
115
0a47030a 116However, using C<\015\012> (or C<\cM\cJ>, or C<\x0D\x0A>) can be tedious
117and unsightly, as well as confusing to those maintaining the code. As
6ab3f9cb 118such, the Socket module supplies the Right Thing for those who want it.
e41182b5 119
120 use Socket qw(:DEFAULT :crlf);
121 print SOCKET "Hi there, client!$CRLF" # RIGHT
122
6ab3f9cb 123When reading from a socket, remember that the default input record
124separator C<$/> is C<\n>, but code like this should recognize C<$/> as
e41182b5 125C<\012> or C<\015\012>:
126
127 while (<SOCKET>) {
128 # ...
129 }
130
6ab3f9cb 131Since both CRLF and LF end in LF, the input record separator can
132be set to LF, and the CR can be stripped later, if present. Better:
e41182b5 133
134 use Socket qw(:DEFAULT :crlf);
135 local($/) = LF; # not needed if $/ is already \012
136
137 while (<SOCKET>) {
138 s/$CR?$LF/\n/; # not sure if socket uses LF or CRLF, OK
139 # s/\015?\012/\n/; # same thing
140 }
141
142And this example is actually better than the previous one even for Unix
143platforms, because now any C<\015>'s (C<\cM>'s) are stripped out
144(and there was much rejoicing).
145
6ab3f9cb 146Similarly, functions that return text data--such as a function that
147fetches a web page--should, in some cases, translate newlines before
148returning the data, if they've not yet been trsnalted to the local
149newline. Often one line of code will suffice:
2ee0eb3c 150
151 $data =~ s/\015?\012/\n/g;
152 return $data;
153
6ab3f9cb 154Some of this may be confusing. Here's a handy reference to the ASCII CR
155and LF characters. You can print it out and stick it in your wallet.
156
157 LF == \012 == \x0A == \cJ == ASCII 10
158 CR == \015 == \x0D == \cM == ASCII 13
159
160 | Unix | DOS | Mac |
161 ---------------------------
162 \n | LF | LF | CR |
163 \r | CR | CR | LF |
164 \n * | LF | CRLF | CR |
165 \r * | CR | CR | LF |
166 ---------------------------
167 * text-mode STDIO
168
169These are just the most common definitions of C<\n> and C<\r> in Perl.
170There may well be others.
171
e41182b5 172
322422de 173=head2 Numbers endianness and Width
174
175Different CPUs store integers and floating point numbers in different
176orders (called I<endianness>) and widths (32-bit and 64-bit being the
177most common). This affects your programs if they attempt to transfer
6ab3f9cb 178numbers in binary format from one CPU architecture to another over some
179channel, usually either "live" via network connection, or by storing the
180numbers to secondary storage such as a disk file.
322422de 181
182Conflicting storage orders make utter mess out of the numbers: if a
183little-endian host (Intel, Alpha) stores 0x12345678 (305419896 in
184decimal), a big-endian host (Motorola, MIPS, Sparc, PA) reads it as
1850x78563412 (2018915346 in decimal). To avoid this problem in network
6ab3f9cb 186(socket) connections use the C<pack> and C<unpack> formats C<n>
187and C<N>, the "network" orders. They are guaranteed to be portable.
322422de 188
189Different widths can cause truncation even between platforms of equal
190endianness: the platform of shorter width loses the upper parts of the
191number. There is no good solution for this problem except to avoid
192transferring or storing raw binary numbers.
193
194One can circumnavigate both these problems in two ways: either
195transfer and store numbers always in text format, instead of raw
6ab3f9cb 196binary, or consider using modules like Data::Dumper (included in
197the standard distribution as of Perl 5.005) and Storable.
198
19799a22 199Also, don't depend on specific values returned from C<printf> and
200C<sprintf>. These in some cases may differ from platform to platform.
322422de 201
433acd8a 202=head2 Files and Filesystems
e41182b5 203
204Most platforms these days structure files in a hierarchical fashion.
205So, it is reasonably safe to assume that any platform supports the
6ab3f9cb 206notion of a "path" to uniquely identify a file on the system. How
207that path is actually written differs.
e41182b5 208
209While they are similar, file path specifications differ between Unix,
495c5fdc 210Windows, S<Mac OS>, OS/2, VMS, VOS, S<RISC OS> and probably others.
211Unix, for example, is one of the few OSes that has the idea of a single
212root directory.
322422de 213
6ab3f9cb 214DOS, OS/2, VMS, VOS, and Windows can work similarly to Unix with C</>
215as path separator, or in their own idiosyncratic ways (such as having
216several root directories and various "unrooted" device files such NIL:
217and LPT:).
322422de 218
219S<Mac OS> uses C<:> as a path separator instead of C</>.
220
6ab3f9cb 221The filesystem may support neither hard links (C<link>) nor
222symbolic links (C<symlink>, C<readlink>, C<lstat>).
433acd8a 223
6ab3f9cb 224The filesystem may support neither access timestamp nor change
433acd8a 225timestamp (meaning that about the only portable timestamp is the
226modification timestamp), or one second granularity of any timestamps
227(e.g. the FAT filesystem limits the time granularity to two seconds).
228
495c5fdc 229VOS perl can emulate Unix filenames with C</> as path separator. The
230native pathname characters greater-than, less-than, number-sign, and
231percent-sign are always accepted.
232
6ab3f9cb 233S<RISC OS> perl can emulate Unix filenames with C</> as path
322422de 234separator, or go native and use C<.> for path separator and C<:> to
6ab3f9cb 235signal filesystems and disk names.
e41182b5 236
6ab3f9cb 237If all this is intimidating, have no (well, maybe only a little) fear.
238There are modules that can help. The File::Spec modules provide
239methods to do the Right Thing on whatever
e41182b5 240platform happens to be running the program.
241
6ab3f9cb 242 use File::Spec::Functions;
243 chdir(updir()); # go up one directory
244 $file = catfile(curdir(), 'temp', 'file.txt');
e41182b5 245 # on Unix and Win32, './temp/file.txt'
246 # on Mac OS, ':temp:file.txt'
247
248File::Spec is available in the standard distribution, as of version
2495.004_05.
250
251In general, production code should not have file paths hardcoded; making
252them user supplied or from a configuration file is better, keeping in mind
253that file path syntax varies on different machines.
254
255This is especially noticeable in scripts like Makefiles and test suites,
256which often assume C</> as a path separator for subdirectories.
257
6ab3f9cb 258Also of use is File::Basename, from the standard distribution, which
e41182b5 259splits a pathname into pieces (base filename, full path to directory,
260and file suffix).
261
19799a22 262Even when on a single platform (if you can call Unix a single platform),
3c075c7d 263remember not to count on the existence or the contents of
264system-specific files or directories, like F</etc/passwd>,
265F</etc/sendmail.conf>, F</etc/resolv.conf>, or even F</tmp/>. For
266example, F</etc/passwd> may exist but it may not contain the encrypted
6ab3f9cb 267passwords because the system is using some form of enhanced security,
3c075c7d 268or it may not contain all the accounts because the system is using NIS.
269If code does need to rely on such a file, include a description of the
270file and its format in the code's documentation, and make it easy for
271the user to override the default location of the file.
272
273Don't assume a text file will end with a newline.
e41182b5 274
dd9f0070 275Do not have two files of the same name with different case, like
3c075c7d 276F<test.pl> and F<Test.pl>, as many platforms have case-insensitive
dd9f0070 277filenames. Also, try not to have non-word characters (except for C<.>)
0a47030a 278in the names, and keep them to the 8.3 convention, for maximum
279portability.
dd9f0070 280
6ab3f9cb 281Likewise, if using the AutoSplit module, try to keep the split functions to
dd9f0070 2828.3 naming and case-insensitive conventions; or, at the very least,
283make it so the resulting files have a unique (case-insensitively)
284first 8 characters.
285
6ab3f9cb 286There certainly can be whitespace in filenames on most systems, but
287some may not allow it. Many systems (DOS, VMS) cannot have more than
288one C<.> in their filenames.
433acd8a 289
290Don't assume C<E<gt>> won't be the first character of a filename.
291Always use C<E<lt>> explicitly to open a file for reading.
0a47030a 292
6ab3f9cb 293 open(FILE, "< $existing_file") or die $!;
0a47030a 294
6ab3f9cb 295If filenames might use strange characters, it is safest to open it
296with C<sysopen> instead of C<open>. C<open> is magic and can
297translate characters like C<E<gt>>, C<E<lt>>, and C<|>, which may
298be the wrong thing to do.
3c075c7d 299
e41182b5 300
301=head2 System Interaction
302
303Not all platforms provide for the notion of a command line, necessarily.
304These are usually platforms that rely on a Graphical User Interface (GUI)
305for user interaction. So a program requiring command lines might not work
306everywhere. But this is probably for the user of the program to deal
6ab3f9cb 307with, so don't stay up late worrying about it.
e41182b5 308
309Some platforms can't delete or rename files that are being held open by
310the system. Remember to C<close> files when you are done with them.
6ab3f9cb 311Don't C<unlink> or C<rename> an open file. Don't C<tie> or C<open> a
312file that is already tied or opened; C<untie> or C<close> first.
e41182b5 313
0a47030a 314Don't open the same file more than once at a time for writing, as some
315operating systems put mandatory locks on such files.
316
e41182b5 317Don't count on a specific environment variable existing in C<%ENV>.
0a47030a 318Don't count on C<%ENV> entries being case-sensitive, or even
e41182b5 319case-preserving.
320
6ab3f9cb 321Don't count on signals for anything.
e41182b5 322
323Don't count on filename globbing. Use C<opendir>, C<readdir>, and
324C<closedir> instead.
325
b8099c3d 326Don't count on per-program environment variables, or per-program current
dd9f0070 327directories.
b8099c3d 328
3c075c7d 329Don't count on specific values of C<$!>.
330
e41182b5 331
332=head2 Interprocess Communication (IPC)
333
334In general, don't directly access the system in code that is meant to be
0a47030a 335portable. That means, no C<system>, C<exec>, C<fork>, C<pipe>, C<``>,
336C<qx//>, C<open> with a C<|>, nor any of the other things that makes being
e41182b5 337a Unix perl hacker worth being.
338
339Commands that launch external processes are generally supported on
340most platforms (though many of them do not support any type of forking),
341but the problem with using them arises from what you invoke with them.
342External tools are often named differently on different platforms, often
343not available in the same location, often accept different arguments,
344often behave differently, and often represent their results in a
345platform-dependent way. Thus you should seldom depend on them to produce
346consistent results.
347
348One especially common bit of Perl code is opening a pipe to sendmail:
349
19799a22 350 open(MAIL, '|/usr/lib/sendmail -t') or die $!;
e41182b5 351
352This is fine for systems programming when sendmail is known to be
353available. But it is not fine for many non-Unix systems, and even
354some Unix systems that may not have sendmail installed. If a portable
19799a22 355solution is needed, see the C<Mail::Send> and C<Mail::Mailer> modules
356in the C<MailTools> distribution. C<Mail::Mailer> provides several
357mailing methods, including mail, sendmail, and direct SMTP
358(via C<Net::SMTP>) if a mail transfer agent is not available.
e41182b5 359
360The rule of thumb for portable code is: Do it all in portable Perl, or
0a47030a 361use a module (that may internally implement it with platform-specific
362code, but expose a common interface).
e41182b5 363
19799a22 364The Unix System V IPC (C<msg*(), sem*(), shm*()>) is not available
365even in all Unix platforms.
366
3c075c7d 367
e41182b5 368=head2 External Subroutines (XS)
369
370XS code, in general, can be made to work with any platform; but dependent
371libraries, header files, etc., might not be readily available or
372portable, or the XS code itself might be platform-specific, just as Perl
373code might be. If the libraries and headers are portable, then it is
374normally reasonable to make sure the XS code is portable, too.
375
376There is a different kind of portability issue with writing XS
0a47030a 377code: availability of a C compiler on the end-user's system. C brings
378with it its own portability issues, and writing XS code will expose you to
e41182b5 379some of those. Writing purely in perl is a comparatively easier way to
380achieve portability.
381
382
383=head2 Standard Modules
384
385In general, the standard modules work across platforms. Notable
6ab3f9cb 386exceptions are the CPAN module (which currently makes connections to external
e41182b5 387programs that may not be available), platform-specific modules (like
6ab3f9cb 388ExtUtils::MM_VMS), and DBM modules.
e41182b5 389
390There is no one DBM module that is available on all platforms.
6ab3f9cb 391SDBM_File and the others are generally available on all Unix and DOSish
392ports, but not in MacPerl, where only NBDM_File and DB_File are
0a47030a 393available.
e41182b5 394
395The good news is that at least some DBM module should be available, and
6ab3f9cb 396AnyDBM_File will use whichever module it can find. Of course, then
e41182b5 397the code needs to be fairly strict, dropping to the lowest common
6ab3f9cb 398denominator (e.g., not exceeding 1K for each record), so that it will
399work with any DBM module. See L<AnyDBM_File> for more details.
e41182b5 400
401
402=head2 Time and Date
403
0a47030a 404The system's notion of time of day and calendar date is controlled in
405widely different ways. Don't assume the timezone is stored in C<$ENV{TZ}>,
406and even if it is, don't assume that you can control the timezone through
407that variable.
e41182b5 408
322422de 409Don't assume that the epoch starts at 00:00:00, January 1, 1970,
6ab3f9cb 410because that is OS- and implementation-specific. It is better to store a date
411in an unambiguous representation. The ISO-8601 standard defines
412"YYYY-MM-DD" as the date format. A text representation (like "1987-12-18")
413can be easily converted into an OS-specific value using a module like
414Date::Parse. An array of values, such as those returned by
322422de 415C<localtime>, can be converted to an OS-specific representation using
6ab3f9cb 416Time::Local.
322422de 417
19799a22 418When calculating specific times, such as for tests in time or date modules,
419it may be appropriate to calculate an offset for the epoch.
420 require Time::Local;
421 $offset = Time::Local::timegm(0, 0, 0, 1, 0, 70);
422The value for C<$offset> in Unix will be C<0>, but in Mac OS will be
423some large number. C<$offset> can then be added to a Unix time value
424to get what should be the proper value on any system.
322422de 425
426=head2 Character sets and character encoding
427
428Assume very little about character sets. Do not assume anything about
6ab3f9cb 429the numerical values (C<ord>, C<chr>) of characters. Do not
322422de 430assume that the alphabetic characters are encoded contiguously (in
3c075c7d 431numerical sense). Do not assume anything about the ordering of the
322422de 432characters. The lowercase letters may come before or after the
433uppercase letters, the lowercase and uppercase may be interlaced so
b1ff3570 434that both 'a' and 'A' come before the 'b', the accented and other
322422de 435international characters may be interlaced so that E<auml> comes
436before the 'b'.
437
438
439=head2 Internationalisation
440
3c075c7d 441If you may assume POSIX (a rather large assumption, that in practice
19799a22 442means Unix), you may read more about the POSIX locale system from
322422de 443L<perllocale>. The locale system at least attempts to make things a
3c075c7d 444little bit more portable, or at least more convenient and
322422de 445native-friendly for non-English users. The system affects character
446sets and encoding, and date and time formatting, among other things.
e41182b5 447
448
449=head2 System Resources
450
0a47030a 451If your code is destined for systems with severely constrained (or
452missing!) virtual memory systems then you want to be I<especially> mindful
453of avoiding wasteful constructs such as:
e41182b5 454
455 # NOTE: this is no longer "bad" in perl5.005
456 for (0..10000000) {} # bad
457 for (my $x = 0; $x <= 10000000; ++$x) {} # good
458
459 @lines = <VERY_LARGE_FILE>; # bad
460
461 while (<FILE>) {$file .= $_} # sometimes bad
0a47030a 462 $file = join('', <FILE>); # better
e41182b5 463
464The last two may appear unintuitive to most people. The first of those
465two constructs repeatedly grows a string, while the second allocates a
466large chunk of memory in one go. On some systems, the latter is more
467efficient that the former.
468
0a47030a 469
e41182b5 470=head2 Security
471
0a47030a 472Most multi-user platforms provide basic levels of security that is usually
473felt at the file-system level. Other platforms usually don't
474(unfortunately). Thus the notion of user id, or "home" directory, or even
475the state of being logged-in, may be unrecognizable on many platforms. If
6ab3f9cb 476you write programs that are security-conscious, it is usually best to know
0a47030a 477what type of system you will be operating under, and write code explicitly
e41182b5 478for that platform (or class of platforms).
479
0a47030a 480
e41182b5 481=head2 Style
482
483For those times when it is necessary to have platform-specific code,
484consider keeping the platform-specific code in one place, making porting
6ab3f9cb 485to other platforms easier. Use the Config module and the special
0a47030a 486variable C<$^O> to differentiate platforms, as described in
487L<"PLATFORMS">.
e41182b5 488
19799a22 489Be careful in the tests you supply with your module or programs. Often
490module code is fully portable, but the tests are not. This occurs
491often when tests spawn off other processes or call external programs
492to aid in the testing, or when (as noted above) the tests assume certain
493things about the filesystem and paths.
6ab3f9cb 494Be careful not to depend on a specific output style for errors,
495such as when checking C<$@> after an C<eval>. Some platforms
496expect a certain output format, and perl on those platforms may
497have been adjusted accordingly. Most specifically, don't anchor
498a regex when testing an error value.
499
500 $@ =~ /^I got an error!/ # may fail
501 $@ =~ /I got an error!/ # probably better
502
e41182b5 503
0a47030a 504=head1 CPAN Testers
e41182b5 505
0a47030a 506Modules uploaded to CPAN are tested by a variety of volunteers on
507different platforms. These CPAN testers are notified by mail of each
e41182b5 508new upload, and reply to the list with PASS, FAIL, NA (not applicable to
0a47030a 509this platform), or UNKNOWN (unknown), along with any relevant notations.
e41182b5 510
511The purpose of the testing is twofold: one, to help developers fix any
0a47030a 512problems in their code that crop up because of lack of testing on other
513platforms; two, to provide users with information about whether or not
514a given module works on a given platform.
e41182b5 515
516=over 4
517
518=item Mailing list: cpan-testers@perl.org
519
6ab3f9cb 520=item Testing results: C<http://www.perl.org/cpan-testers/>
e41182b5 521
522=back
523
524
525=head1 PLATFORMS
526
527As of version 5.002, Perl is built with a C<$^O> variable that
528indicates the operating system it was built on. This was implemented
529to help speed up code that would otherwise have to C<use Config;> and
530use the value of C<$Config{'osname'}>. Of course, to get
531detailed information about the system, looking into C<%Config> is
532certainly recommended.
533
6ab3f9cb 534C<%Config> cannot always be trusted, however,
535because it is built at compile time, and if perl was built in once
536place and transferred elsewhere, some values may be off, or the
537values may have been edited after the fact.
538
539
e41182b5 540=head2 Unix
541
542Perl works on a bewildering variety of Unix and Unix-like platforms (see
543e.g. most of the files in the F<hints/> directory in the source code kit).
544On most of these systems, the value of C<$^O> (hence C<$Config{'osname'}>,
545too) is determined by lowercasing and stripping punctuation from the first
0a47030a 546field of the string returned by typing C<uname -a> (or a similar command)
547at the shell prompt. Here, for example, are a few of the more popular
548Unix flavors:
e41182b5 549
19799a22 550 uname $^O $Config{'archname'}
6ab3f9cb 551 --------------------------------------------
19799a22 552 AIX aix aix
6ab3f9cb 553 BSD/OS bsdos i386-bsdos
554 dgux dgux AViiON-dgux
555 DYNIX/ptx dynixptx i386-dynixptx
19799a22 556 FreeBSD freebsd freebsd-i386
557 Linux linux i386-linux
6ab3f9cb 558 Linux linux i586-linux
559 Linux linux ppc-linux
19799a22 560 HP-UX hpux PA-RISC1.1
561 IRIX irix irix
6ab3f9cb 562 openbsd openbsd i386-openbsd
19799a22 563 OSF1 dec_osf alpha-dec_osf
6ab3f9cb 564 reliantunix-n svr4 RM400-svr4
565 SCO_SV sco_sv i386-sco_sv
566 SINIX-N svr4 RM400-svr4
567 sn4609 unicos CRAY_C90-unicos
568 sn6521 unicosmk t3e-unicosmk
569 sn9617 unicos CRAY_J90-unicos
19799a22 570 SunOS solaris sun4-solaris
571 SunOS solaris i86pc-solaris
572 SunOS4 sunos sun4-sunos
e41182b5 573
322422de 574Note that because the C<$Config{'archname'}> may depend on the hardware
575architecture it may vary quite a lot, much more than the C<$^O>.
e41182b5 576
6ab3f9cb 577
e41182b5 578=head2 DOS and Derivatives
579
580Perl has long been ported to PC style microcomputers running under
581systems like PC-DOS, MS-DOS, OS/2, and most Windows platforms you can
582bring yourself to mention (except for Windows CE, if you count that).
583Users familiar with I<COMMAND.COM> and/or I<CMD.EXE> style shells should
584be aware that each of these file specifications may have subtle
585differences:
586
587 $filespec0 = "c:/foo/bar/file.txt";
588 $filespec1 = "c:\\foo\\bar\\file.txt";
589 $filespec2 = 'c:\foo\bar\file.txt';
590 $filespec3 = 'c:\\foo\\bar\\file.txt';
591
592System calls accept either C</> or C<\> as the path separator. However,
593many command-line utilities of DOS vintage treat C</> as the option
594prefix, so they may get confused by filenames containing C</>. Aside
595from calling any external programs, C</> will work just fine, and
596probably better, as it is more consistent with popular usage, and avoids
597the problem of remembering what to backwhack and what not to.
598
0a47030a 599The DOS FAT filesystem can only accommodate "8.3" style filenames. Under
e41182b5 600the "case insensitive, but case preserving" HPFS (OS/2) and NTFS (NT)
0a47030a 601filesystems you may have to be careful about case returned with functions
e41182b5 602like C<readdir> or used with functions like C<open> or C<opendir>.
603
604DOS also treats several filenames as special, such as AUX, PRN, NUL, CON,
605COM1, LPT1, LPT2 etc. Unfortunately these filenames won't even work
606if you include an explicit directory prefix, in some cases. It is best
607to avoid such filenames, if you want your code to be portable to DOS
608and its derivatives.
609
610Users of these operating systems may also wish to make use of
6ab3f9cb 611scripts such as F<pl2bat.bat> or F<pl2cmd> as appropriate to
e41182b5 612put wrappers around your scripts.
613
614Newline (C<\n>) is translated as C<\015\012> by STDIO when reading from
6ab3f9cb 615and writing to files (see L<"Newlines">). C<binmode(FILEHANDLE)>
616will keep C<\n> translated as C<\012> for that filehandle. Since it is a
617no-op on other systems, C<binmode> should be used for cross-platform code
618that deals with binary data.
e41182b5 619
620The C<$^O> variable and the C<$Config{'archname'}> values for various
621DOSish perls are as follows:
622
623 OS $^O $Config{'archname'}
624 --------------------------------------------
625 MS-DOS dos
626 PC-DOS dos
627 OS/2 os2
628 Windows 95 MSWin32 MSWin32-x86
6ab3f9cb 629 Windows 98 MSWin32 MSWin32-x86
e41182b5 630 Windows NT MSWin32 MSWin32-x86
6ab3f9cb 631 Windows NT MSWin32 MSWin32-ALPHA
e41182b5 632 Windows NT MSWin32 MSWin32-ppc
633
634Also see:
635
636=over 4
637
638=item The djgpp environment for DOS, C<http://www.delorie.com/djgpp/>
639
640=item The EMX environment for DOS, OS/2, etc. C<emx@iaehv.nl>,
2ee0eb3c 641C<http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/index.html> or
642C<ftp://hobbes.nmsu.edu/pub/os2/dev/emx>
e41182b5 643
644=item Build instructions for Win32, L<perlwin32>.
645
646=item The ActiveState Pages, C<http://www.activestate.com/>
647
648=back
649
650
dd9f0070 651=head2 S<Mac OS>
e41182b5 652
653Any module requiring XS compilation is right out for most people, because
654MacPerl is built using non-free (and non-cheap!) compilers. Some XS
655modules that can work with MacPerl are built and distributed in binary
6ab3f9cb 656form on CPAN.
e41182b5 657
658Directories are specified as:
659
660 volume:folder:file for absolute pathnames
661 volume:folder: for absolute pathnames
662 :folder:file for relative pathnames
663 :folder: for relative pathnames
664 :file for relative pathnames
665 file for relative pathnames
666
667Files in a directory are stored in alphabetical order. Filenames are
6ab3f9cb 668limited to 31 characters, and may include any character except for
669null and C<:>, which is reserved as path separator.
e41182b5 670
0a47030a 671Instead of C<flock>, see C<FSpSetFLock> and C<FSpRstFLock> in the
6ab3f9cb 672Mac::Files module, or C<chmod(0444, ...)> and C<chmod(0666, ...)>.
e41182b5 673
674In the MacPerl application, you can't run a program from the command line;
675programs that expect C<@ARGV> to be populated can be edited with something
676like the following, which brings up a dialog box asking for the command
677line arguments.
678
679 if (!@ARGV) {
680 @ARGV = split /\s+/, MacPerl::Ask('Arguments?');
681 }
682
683A MacPerl script saved as a droplet will populate C<@ARGV> with the full
684pathnames of the files dropped onto the script.
685
686Mac users can use programs on a kind of command line under MPW (Macintosh
687Programmer's Workshop, a free development environment from Apple).
688MacPerl was first introduced as an MPW tool, and MPW can be used like a
689shell:
690
691 perl myscript.plx some arguments
692
693ToolServer is another app from Apple that provides access to MPW tools
0a47030a 694from MPW and the MacPerl app, which allows MacPerl programs to use
e41182b5 695C<system>, backticks, and piped C<open>.
696
697"S<Mac OS>" is the proper name for the operating system, but the value
698in C<$^O> is "MacOS". To determine architecture, version, or whether
699the application or MPW tool version is running, check:
700
701 $is_app = $MacPerl::Version =~ /App/;
702 $is_tool = $MacPerl::Version =~ /MPW/;
703 ($version) = $MacPerl::Version =~ /^(\S+)/;
704 $is_ppc = $MacPerl::Architecture eq 'MacPPC';
705 $is_68k = $MacPerl::Architecture eq 'Mac68K';
706
6ab3f9cb 707S<Mac OS X> and S<Mac OS X Server>, based on NeXT's OpenStep OS, will
708(in theory) be able to run MacPerl natively, under the "Classic"
709environment. The new "Cocoa" environment (formerly called the "Yellow Box")
710may run a slightly modified version of MacPerl, using the Carbon interfaces.
711
712S<Mac OS X Server> and its Open Source version, Darwin, both run Unix
713perl natively (with a small number of patches). Full support for these
714is slated for perl5.006.
715
e41182b5 716
717Also see:
718
719=over 4
720
6ab3f9cb 721=item The MacPerl Pages, C<http://www.macperl.com/>.
e41182b5 722
6ab3f9cb 723=item The MacPerl mailing lists, C<http://www.macperl.org/>.
724
725=item MacPerl Module Porters, C<http://pudge.net/mmp/>.
e41182b5 726
727=back
728
729
730=head2 VMS
731
732Perl on VMS is discussed in F<vms/perlvms.pod> in the perl distribution.
0a47030a 733Note that perl on VMS can accept either VMS- or Unix-style file
e41182b5 734specifications as in either of the following:
735
736 $ perl -ne "print if /perl_setup/i" SYS$LOGIN:LOGIN.COM
737 $ perl -ne "print if /perl_setup/i" /sys$login/login.com
738
739but not a mixture of both as in:
740
741 $ perl -ne "print if /perl_setup/i" sys$login:/login.com
742 Can't open sys$login:/login.com: file specification syntax error
743
744Interacting with Perl from the Digital Command Language (DCL) shell
745often requires a different set of quotation marks than Unix shells do.
746For example:
747
748 $ perl -e "print ""Hello, world.\n"""
749 Hello, world.
750
751There are a number of ways to wrap your perl scripts in DCL .COM files if
752you are so inclined. For example:
753
754 $ write sys$output "Hello from DCL!"
755 $ if p1 .eqs. ""
756 $ then perl -x 'f$environment("PROCEDURE")
757 $ else perl -x - 'p1 'p2 'p3 'p4 'p5 'p6 'p7 'p8
758 $ deck/dollars="__END__"
759 #!/usr/bin/perl
760
761 print "Hello from Perl!\n";
762
763 __END__
764 $ endif
765
766Do take care with C<$ ASSIGN/nolog/user SYS$COMMAND: SYS$INPUT> if your
767perl-in-DCL script expects to do things like C<$read = E<lt>STDINE<gt>;>.
768
769Filenames are in the format "name.extension;version". The maximum
770length for filenames is 39 characters, and the maximum length for
771extensions is also 39 characters. Version is a number from 1 to
77232767. Valid characters are C</[A-Z0-9$_-]/>.
773
774VMS' RMS filesystem is case insensitive and does not preserve case.
775C<readdir> returns lowercased filenames, but specifying a file for
b8099c3d 776opening remains case insensitive. Files without extensions have a
e41182b5 777trailing period on them, so doing a C<readdir> with a file named F<A.;5>
0a47030a 778will return F<a.> (though that file could be opened with
779C<open(FH, 'A')>).
e41182b5 780
f34d0673 781RMS had an eight level limit on directory depths from any rooted logical
dd9f0070 782(allowing 16 levels overall) prior to VMS 7.2. Hence
783C<PERL_ROOT:[LIB.2.3.4.5.6.7.8]> is a valid directory specification but
784C<PERL_ROOT:[LIB.2.3.4.5.6.7.8.9]> is not. F<Makefile.PL> authors might
785have to take this into account, but at least they can refer to the former
f34d0673 786as C</PERL_ROOT/lib/2/3/4/5/6/7/8/>.
e41182b5 787
6ab3f9cb 788The VMS::Filespec module, which gets installed as part of the build
0a47030a 789process on VMS, is a pure Perl module that can easily be installed on
790non-VMS platforms and can be helpful for conversions to and from RMS
791native formats.
e41182b5 792
793What C<\n> represents depends on the type of file that is open. It could
794be C<\015>, C<\012>, C<\015\012>, or nothing. Reading from a file
795translates newlines to C<\012>, unless C<binmode> was executed on that
796handle, just like DOSish perls.
797
798TCP/IP stacks are optional on VMS, so socket routines might not be
799implemented. UDP sockets may not be supported.
800
801The value of C<$^O> on OpenVMS is "VMS". To determine the architecture
802that you are running on without resorting to loading all of C<%Config>
803you can examine the content of the C<@INC> array like so:
804
805 if (grep(/VMS_AXP/, @INC)) {
806 print "I'm on Alpha!\n";
6ab3f9cb 807
e41182b5 808 } elsif (grep(/VMS_VAX/, @INC)) {
809 print "I'm on VAX!\n";
6ab3f9cb 810
e41182b5 811 } else {
812 print "I'm not so sure about where $^O is...\n";
813 }
814
6ab3f9cb 815On VMS perl determines the UTC offset from the C<SYS$TIMEZONE_DIFFERENTIAL>
816logical name. Though the VMS epoch began at 17-NOV-1858 00:00:00.00,
817calls to C<localtime> are adjusted to count offsets from
81801-JAN-1970 00:00:00.00 just like Unix.
819
e41182b5 820Also see:
821
822=over 4
823
824=item L<perlvms.pod>
825
6ab3f9cb 826=item vmsperl list, C<majordomo@perl.org>
e41182b5 827
6ab3f9cb 828Put the words C<subscribe vmsperl> in message body.
e41182b5 829
830=item vmsperl on the web, C<http://www.sidhe.org/vmsperl/index.html>
831
832=back
833
834
495c5fdc 835=head2 VOS
836
837Perl on VOS is discussed in F<README.vos> in the perl distribution.
838Note that perl on VOS can accept either VOS- or Unix-style file
839specifications as in either of the following:
840
841 $ perl -ne "print if /perl_setup/i" >system>notices
842 $ perl -ne "print if /perl_setup/i" /system/notices
843
844or even a mixture of both as in:
845
846 $ perl -ne "print if /perl_setup/i" >system/notices
847
848Note that even though VOS allows the slash character to appear in object
849names, because the VOS port of Perl interprets it as a pathname
850delimiting character, VOS files, directories, or links whose names
851contain a slash character cannot be processed. Such files must be
852renamed before they can be processed by Perl.
853
2ee0eb3c 854The following C functions are unimplemented on VOS, and any attempt by
495c5fdc 855Perl to use them will result in a fatal error message and an immediate
2ee0eb3c 856exit from Perl: dup, do_aspawn, do_spawn, fork, waitpid. Once these
857functions become available in the VOS POSIX.1 implementation, you can
858either recompile and rebind Perl, or you can download a newer port from
859ftp.stratus.com.
495c5fdc 860
861The value of C<$^O> on VOS is "VOS". To determine the architecture that
862you are running on without resorting to loading all of C<%Config> you
863can examine the content of the C<@INC> array like so:
864
865 if (grep(/VOS/, @INC)) {
866 print "I'm on a Stratus box!\n";
867 } else {
868 print "I'm not on a Stratus box!\n";
869 die;
870 }
871
872 if (grep(/860/, @INC)) {
873 print "This box is a Stratus XA/R!\n";
6ab3f9cb 874
495c5fdc 875 } elsif (grep(/7100/, @INC)) {
876 print "This box is a Stratus HP 7100 or 8000!\n";
6ab3f9cb 877
495c5fdc 878 } elsif (grep(/8000/, @INC)) {
879 print "This box is a Stratus HP 8000!\n";
6ab3f9cb 880
495c5fdc 881 } else {
882 print "This box is a Stratus 68K...\n";
883 }
884
885Also see:
886
887=over 4
888
889=item L<README.vos>
890
891=item VOS mailing list
892
893There is no specific mailing list for Perl on VOS. You can post
894comments to the comp.sys.stratus newsgroup, or subscribe to the general
895Stratus mailing list. Send a letter with "Subscribe Info-Stratus" in
896the message body to majordomo@list.stratagy.com.
897
898=item VOS Perl on the web at C<http://ftp.stratus.com/pub/vos/vos.html>
899
900=back
901
902
e41182b5 903=head2 EBCDIC Platforms
904
905Recent versions of Perl have been ported to platforms such as OS/400 on
7c5ffed3 906AS/400 minicomputers as well as OS/390 & VM/ESA for IBM Mainframes. Such
907computers use EBCDIC character sets internally (usually Character Code
908Set ID 00819 for OS/400 and IBM-1047 for OS/390 & VM/ESA). Note that on
909the mainframe perl currently works under the "Unix system services
910for OS/390" (formerly known as OpenEdition) and VM/ESA OpenEdition.
e41182b5 911
7c5ffed3 912As of R2.5 of USS for OS/390 and Version 2.3 of VM/ESA these Unix
913sub-systems do not support the C<#!> shebang trick for script invocation.
914Hence, on OS/390 and VM/ESA perl scripts can be executed with a header
915similar to the following simple script:
e41182b5 916
917 : # use perl
918 eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
919 if 0;
920 #!/usr/local/bin/perl # just a comment really
921
922 print "Hello from perl!\n";
923
6ab3f9cb 924On the AS/400, assuming that PERL5 is in your library list, you may need
925to wrap your perl scripts in a CL procedure to invoke them like so:
926
927 BEGIN
928 CALL PGM(PERL5/PERL) PARM('/QOpenSys/hello.pl')
929 ENDPGM
930
931This will invoke the perl script F<hello.pl> in the root of the
932QOpenSys file system. On the AS/400 calls to C<system> or backticks
933must use CL syntax.
934
e41182b5 935On these platforms, bear in mind that the EBCDIC character set may have
0a47030a 936an effect on what happens with some perl functions (such as C<chr>,
937C<pack>, C<print>, C<printf>, C<ord>, C<sort>, C<sprintf>, C<unpack>), as
938well as bit-fiddling with ASCII constants using operators like C<^>, C<&>
939and C<|>, not to mention dealing with socket interfaces to ASCII computers
6ab3f9cb 940(see L<"Newlines">).
e41182b5 941
942Fortunately, most web servers for the mainframe will correctly translate
943the C<\n> in the following statement to its ASCII equivalent (note that
7c5ffed3 944C<\r> is the same under both Unix and OS/390 & VM/ESA):
e41182b5 945
946 print "Content-type: text/html\r\n\r\n";
947
948The value of C<$^O> on OS/390 is "os390".
949
7c5ffed3 950The value of C<$^O> on VM/ESA is "vmesa".
3c075c7d 951
e41182b5 952Some simple tricks for determining if you are running on an EBCDIC
953platform could include any of the following (perhaps all):
954
955 if ("\t" eq "\05") { print "EBCDIC may be spoken here!\n"; }
956
957 if (ord('A') == 193) { print "EBCDIC may be spoken here!\n"; }
958
959 if (chr(169) eq 'z') { print "EBCDIC may be spoken here!\n"; }
960
961Note that one thing you may not want to rely on is the EBCDIC encoding
0a47030a 962of punctuation characters since these may differ from code page to code
963page (and once your module or script is rumoured to work with EBCDIC,
964folks will want it to work with all EBCDIC character sets).
e41182b5 965
966Also see:
967
968=over 4
969
970=item perl-mvs list
971
972The perl-mvs@perl.org list is for discussion of porting issues as well as
973general usage issues for all EBCDIC Perls. Send a message body of
974"subscribe perl-mvs" to majordomo@perl.org.
975
0a47030a 976=item AS/400 Perl information at C<http://as400.rochester.ibm.com/>
e41182b5 977
978=back
979
b8099c3d 980
981=head2 Acorn RISC OS
982
0a47030a 983As Acorns use ASCII with newlines (C<\n>) in text files as C<\012> like
984Unix and Unix filename emulation is turned on by default, it is quite
985likely that most simple scripts will work "out of the box". The native
6ab3f9cb 986filesystem is modular, and individual filesystems are free to be
0a47030a 987case-sensitive or insensitive, and are usually case-preserving. Some
6ab3f9cb 988native filesystems have name length limits which file and directory
989names are silently truncated to fit. Scripts should be aware that the
990standard filesystem currently has a name length limit of B<10>
991characters, with up to 77 items in a directory, but other filesystems
0a47030a 992may not impose such limitations.
b8099c3d 993
994Native filenames are of the form
995
6ab3f9cb 996 Filesystem#Special_Field::DiskName.$.Directory.Directory.File
dd9f0070 997
b8099c3d 998where
999
1000 Special_Field is not usually present, but may contain . and $ .
1001 Filesystem =~ m|[A-Za-z0-9_]|
1002 DsicName =~ m|[A-Za-z0-9_/]|
1003 $ represents the root directory
1004 . is the path separator
1005 @ is the current directory (per filesystem but machine global)
1006 ^ is the parent directory
1007 Directory and File =~ m|[^\0- "\.\$\%\&:\@\\^\|\177]+|
1008
1009The default filename translation is roughly C<tr|/.|./|;>
1010
6ab3f9cb 1011Note that C<"ADFS::HardDisk.$.File" ne 'ADFS::HardDisk.$.File'> and that
0a47030a 1012the second stage of C<$> interpolation in regular expressions will fall
1013foul of the C<$.> if scripts are not careful.
1014
1015Logical paths specified by system variables containing comma-separated
1016search lists are also allowed, hence C<System:Modules> is a valid
1017filename, and the filesystem will prefix C<Modules> with each section of
6ab3f9cb 1018C<System$Path> until a name is made that points to an object on disk.
0a47030a 1019Writing to a new file C<System:Modules> would only be allowed if
1020C<System$Path> contains a single item list. The filesystem will also
1021expand system variables in filenames if enclosed in angle brackets, so
1022C<E<lt>System$DirE<gt>.Modules> would look for the file
1023S<C<$ENV{'System$Dir'} . 'Modules'>>. The obvious implication of this is
3c075c7d 1024that B<fully qualified filenames can start with C<E<lt>E<gt>>> and should
0a47030a 1025be protected when C<open> is used for input.
b8099c3d 1026
1027Because C<.> was in use as a directory separator and filenames could not
1028be assumed to be unique after 10 characters, Acorn implemented the C
1029compiler to strip the trailing C<.c> C<.h> C<.s> and C<.o> suffix from
1030filenames specified in source code and store the respective files in
1031subdirectories named after the suffix. Hence files are translated:
1032
1033 foo.h h.foo
1034 C:foo.h C:h.foo (logical path variable)
1035 sys/os.h sys.h.os (C compiler groks Unix-speak)
1036 10charname.c c.10charname
1037 10charname.o o.10charname
1038 11charname_.c c.11charname (assuming filesystem truncates at 10)
1039
1040The Unix emulation library's translation of filenames to native assumes
0a47030a 1041that this sort of translation is required, and allows a user defined list
1042of known suffixes which it will transpose in this fashion. This may
1043appear transparent, but consider that with these rules C<foo/bar/baz.h>
1044and C<foo/bar/h/baz> both map to C<foo.bar.h.baz>, and that C<readdir> and
1045C<glob> cannot and do not attempt to emulate the reverse mapping. Other
6ab3f9cb 1046C<.>'s in filenames are translated to C</>.
0a47030a 1047
1048As implied above the environment accessed through C<%ENV> is global, and
1049the convention is that program specific environment variables are of the
6ab3f9cb 1050form C<Program$Name>. Each filesystem maintains a current directory,
1051and the current filesystem's current directory is the B<global> current
0a47030a 1052directory. Consequently, sociable scripts don't change the current
1053directory but rely on full pathnames, and scripts (and Makefiles) cannot
1054assume that they can spawn a child process which can change the current
1055directory without affecting its parent (and everyone else for that
1056matter).
1057
1058As native operating system filehandles are global and currently are
1059allocated down from 255, with 0 being a reserved value the Unix emulation
1060library emulates Unix filehandles. Consequently, you can't rely on
1061passing C<STDIN>, C<STDOUT>, or C<STDERR> to your children.
1062
1063The desire of users to express filenames of the form
1064C<E<lt>Foo$DirE<gt>.Bar> on the command line unquoted causes problems,
1065too: C<``> command output capture has to perform a guessing game. It
1066assumes that a string C<E<lt>[^E<lt>E<gt>]+\$[^E<lt>E<gt>]E<gt>> is a
1067reference to an environment variable, whereas anything else involving
1068C<E<lt>> or C<E<gt>> is redirection, and generally manages to be 99%
1069right. Of course, the problem remains that scripts cannot rely on any
1070Unix tools being available, or that any tools found have Unix-like command
1071line arguments.
1072
1073Extensions and XS are, in theory, buildable by anyone using free tools.
1074In practice, many don't, as users of the Acorn platform are used to binary
1075distribution. MakeMaker does run, but no available make currently copes
1076with MakeMaker's makefiles; even if/when this is fixed, the lack of a
1077Unix-like shell can cause problems with makefile rules, especially lines
1078of the form C<cd sdbm && make all>, and anything using quoting.
b8099c3d 1079
1080"S<RISC OS>" is the proper name for the operating system, but the value
1081in C<$^O> is "riscos" (because we don't like shouting).
1082
b8099c3d 1083
e41182b5 1084=head2 Other perls
1085
b8099c3d 1086Perl has been ported to a variety of platforms that do not fit into any of
6ab3f9cb 1087the above categories. Some, such as AmigaOS, Atari MiNT, BeOS, HP MPE/iX,
1088QNX, Plan 9, and VOS, have been well-integrated into the standard Perl source
1089code kit. You may need to see the F<ports/> directory on CPAN for
1090information, and possibly binaries, for the likes of: aos, Atari ST, lynxos,
1091riscos, Novell Netware, Tandem Guardian, I<etc.> (yes we know that some of
1092these OSes may fall under the Unix category, but we are not a standards body.)
e41182b5 1093
1094See also:
1095
1096=over 4
1097
1098=item Atari, Guido Flohr's page C<http://stud.uni-sb.de/~gufl0000/>
1099
1100=item HP 300 MPE/iX C<http://www.cccd.edu/~markb/perlix.html>
1101
1102=item Novell Netware
1103
6ab3f9cb 1104A free perl5-based PERL.NLM for Novell Netware is available in
1105precompiled binary and source code form from C<http://www.novell.com/>
1106as well as from CPAN.
e41182b5 1107
1108=back
1109
1110
1111=head1 FUNCTION IMPLEMENTATIONS
1112
1113Listed below are functions unimplemented or implemented differently on
1114various platforms. Following each description will be, in parentheses, a
1115list of platforms that the description applies to.
1116
1117The list may very well be incomplete, or wrong in some places. When in
1118doubt, consult the platform-specific README files in the Perl source
1119distribution, and other documentation resources for a given port.
1120
0a47030a 1121Be aware, moreover, that even among Unix-ish systems there are variations.
e41182b5 1122
1123For many functions, you can also query C<%Config>, exported by default
6ab3f9cb 1124from the Config module. For example, to check if the platform has the C<lstat>
1125call, check C<$Config{'d_lstat'}>. See L<Config> for a full
0a47030a 1126description of available variables.
e41182b5 1127
1128
1129=head2 Alphabetical Listing of Perl Functions
1130
1131=over 8
1132
1133=item -X FILEHANDLE
1134
1135=item -X EXPR
1136
1137=item -X
1138
1139C<-r>, C<-w>, and C<-x> have only a very limited meaning; directories
1140and applications are executable, and there are no uid/gid
1141considerations. C<-o> is not supported. (S<Mac OS>)
1142
1143C<-r>, C<-w>, C<-x>, and C<-o> tell whether or not file is accessible,
1144which may not reflect UIC-based file protections. (VMS)
1145
b8099c3d 1146C<-s> returns the size of the data fork, not the total size of data fork
1147plus resource fork. (S<Mac OS>).
1148
1149C<-s> by name on an open file will return the space reserved on disk,
1150rather than the current extent. C<-s> on an open filehandle returns the
1151current size. (S<RISC OS>)
1152
e41182b5 1153C<-R>, C<-W>, C<-X>, C<-O> are indistinguishable from C<-r>, C<-w>,
b8099c3d 1154C<-x>, C<-o>. (S<Mac OS>, Win32, VMS, S<RISC OS>)
e41182b5 1155
1156C<-b>, C<-c>, C<-k>, C<-g>, C<-p>, C<-u>, C<-A> are not implemented.
1157(S<Mac OS>)
1158
1159C<-g>, C<-k>, C<-l>, C<-p>, C<-u>, C<-A> are not particularly meaningful.
b8099c3d 1160(Win32, VMS, S<RISC OS>)
e41182b5 1161
1162C<-d> is true if passed a device spec without an explicit directory.
1163(VMS)
1164
1165C<-T> and C<-B> are implemented, but might misclassify Mac text files
0a47030a 1166with foreign characters; this is the case will all platforms, but may
1167affect S<Mac OS> often. (S<Mac OS>)
e41182b5 1168
1169C<-x> (or C<-X>) determine if a file ends in one of the executable
1170suffixes. C<-S> is meaningless. (Win32)
1171
b8099c3d 1172C<-x> (or C<-X>) determine if a file has an executable file type.
1173(S<RISC OS>)
1174
e41182b5 1175=item binmode FILEHANDLE
1176
b8099c3d 1177Meaningless. (S<Mac OS>, S<RISC OS>)
e41182b5 1178
1179Reopens file and restores pointer; if function fails, underlying
1180filehandle may be closed, or pointer may be in a different position.
1181(VMS)
1182
1183The value returned by C<tell> may be affected after the call, and
1184the filehandle may be flushed. (Win32)
1185
1186=item chmod LIST
1187
1188Only limited meaning. Disabling/enabling write permission is mapped to
1189locking/unlocking the file. (S<Mac OS>)
1190
1191Only good for changing "owner" read-write access, "group", and "other"
1192bits are meaningless. (Win32)
1193
b8099c3d 1194Only good for changing "owner" and "other" read-write access. (S<RISC OS>)
1195
495c5fdc 1196Access permissions are mapped onto VOS access-control list changes. (VOS)
1197
e41182b5 1198=item chown LIST
1199
495c5fdc 1200Not implemented. (S<Mac OS>, Win32, Plan9, S<RISC OS>, VOS)
e41182b5 1201
1202Does nothing, but won't fail. (Win32)
1203
1204=item chroot FILENAME
1205
1206=item chroot
1207
7c5ffed3 1208Not implemented. (S<Mac OS>, Win32, VMS, Plan9, S<RISC OS>, VOS, VM/ESA)
e41182b5 1209
1210=item crypt PLAINTEXT,SALT
1211
1212May not be available if library or source was not provided when building
b8099c3d 1213perl. (Win32)
e41182b5 1214
495c5fdc 1215Not implemented. (VOS)
1216
e41182b5 1217=item dbmclose HASH
1218
495c5fdc 1219Not implemented. (VMS, Plan9, VOS)
e41182b5 1220
1221=item dbmopen HASH,DBNAME,MODE
1222
495c5fdc 1223Not implemented. (VMS, Plan9, VOS)
e41182b5 1224
1225=item dump LABEL
1226
b8099c3d 1227Not useful. (S<Mac OS>, S<RISC OS>)
e41182b5 1228
1229Not implemented. (Win32)
1230
b8099c3d 1231Invokes VMS debugger. (VMS)
e41182b5 1232
1233=item exec LIST
1234
1235Not implemented. (S<Mac OS>)
1236
7c5ffed3 1237Implemented via Spawn. (VM/ESA)
3c075c7d 1238
e41182b5 1239=item fcntl FILEHANDLE,FUNCTION,SCALAR
1240
1241Not implemented. (Win32, VMS)
1242
1243=item flock FILEHANDLE,OPERATION
1244
495c5fdc 1245Not implemented (S<Mac OS>, VMS, S<RISC OS>, VOS).
e41182b5 1246
1247Available only on Windows NT (not on Windows 95). (Win32)
1248
1249=item fork
1250
7c5ffed3 1251Not implemented. (S<Mac OS>, Win32, AmigaOS, S<RISC OS>, VOS, VM/ESA)
e41182b5 1252
1253=item getlogin
1254
b8099c3d 1255Not implemented. (S<Mac OS>, S<RISC OS>)
e41182b5 1256
1257=item getpgrp PID
1258
495c5fdc 1259Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VOS)
e41182b5 1260
1261=item getppid
1262
b8099c3d 1263Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
e41182b5 1264
1265=item getpriority WHICH,WHO
1266
7c5ffed3 1267Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VOS, VM/ESA)
e41182b5 1268
1269=item getpwnam NAME
1270
1271Not implemented. (S<Mac OS>, Win32)
1272
b8099c3d 1273Not useful. (S<RISC OS>)
1274
e41182b5 1275=item getgrnam NAME
1276
b8099c3d 1277Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
e41182b5 1278
1279=item getnetbyname NAME
1280
1281Not implemented. (S<Mac OS>, Win32, Plan9)
1282
1283=item getpwuid UID
1284
1285Not implemented. (S<Mac OS>, Win32)
1286
b8099c3d 1287Not useful. (S<RISC OS>)
1288
e41182b5 1289=item getgrgid GID
1290
b8099c3d 1291Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
e41182b5 1292
1293=item getnetbyaddr ADDR,ADDRTYPE
1294
1295Not implemented. (S<Mac OS>, Win32, Plan9)
1296
1297=item getprotobynumber NUMBER
1298
1299Not implemented. (S<Mac OS>)
1300
1301=item getservbyport PORT,PROTO
1302
1303Not implemented. (S<Mac OS>)
1304
1305=item getpwent
1306
7c5ffed3 1307Not implemented. (S<Mac OS>, Win32, VM/ESA)
e41182b5 1308
1309=item getgrent
1310
7c5ffed3 1311Not implemented. (S<Mac OS>, Win32, VMS, VM/ESA)
e41182b5 1312
1313=item gethostent
1314
1315Not implemented. (S<Mac OS>, Win32)
1316
1317=item getnetent
1318
1319Not implemented. (S<Mac OS>, Win32, Plan9)
1320
1321=item getprotoent
1322
1323Not implemented. (S<Mac OS>, Win32, Plan9)
1324
1325=item getservent
1326
1327Not implemented. (Win32, Plan9)
1328
1329=item setpwent
1330
b8099c3d 1331Not implemented. (S<Mac OS>, Win32, S<RISC OS>)
e41182b5 1332
1333=item setgrent
1334
b8099c3d 1335Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
e41182b5 1336
1337=item sethostent STAYOPEN
1338
b8099c3d 1339Not implemented. (S<Mac OS>, Win32, Plan9, S<RISC OS>)
e41182b5 1340
1341=item setnetent STAYOPEN
1342
b8099c3d 1343Not implemented. (S<Mac OS>, Win32, Plan9, S<RISC OS>)
e41182b5 1344
1345=item setprotoent STAYOPEN
1346
b8099c3d 1347Not implemented. (S<Mac OS>, Win32, Plan9, S<RISC OS>)
e41182b5 1348
1349=item setservent STAYOPEN
1350
b8099c3d 1351Not implemented. (Plan9, Win32, S<RISC OS>)
e41182b5 1352
1353=item endpwent
1354
7c5ffed3 1355Not implemented. (S<Mac OS>, Win32, VM/ESA)
e41182b5 1356
1357=item endgrent
1358
7c5ffed3 1359Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VM/ESA)
e41182b5 1360
1361=item endhostent
1362
1363Not implemented. (S<Mac OS>, Win32)
1364
1365=item endnetent
1366
1367Not implemented. (S<Mac OS>, Win32, Plan9)
1368
1369=item endprotoent
1370
1371Not implemented. (S<Mac OS>, Win32, Plan9)
1372
1373=item endservent
1374
1375Not implemented. (Plan9, Win32)
1376
1377=item getsockopt SOCKET,LEVEL,OPTNAME
1378
1379Not implemented. (S<Mac OS>, Plan9)
1380
1381=item glob EXPR
1382
1383=item glob
1384
1385Globbing built-in, but only C<*> and C<?> metacharacters are supported.
1386(S<Mac OS>)
1387
0a47030a 1388Features depend on external perlglob.exe or perlglob.bat. May be
1389overridden with something like File::DosGlob, which is recommended.
1390(Win32)
e41182b5 1391
b8099c3d 1392Globbing built-in, but only C<*> and C<?> metacharacters are supported.
0a47030a 1393Globbing relies on operating system calls, which may return filenames
1394in any order. As most filesystems are case-insensitive, even "sorted"
1395filenames will not be in case-sensitive order. (S<RISC OS>)
b8099c3d 1396
e41182b5 1397=item ioctl FILEHANDLE,FUNCTION,SCALAR
1398
1399Not implemented. (VMS)
1400
1401Available only for socket handles, and it does what the ioctlsocket() call
1402in the Winsock API does. (Win32)
1403
b8099c3d 1404Available only for socket handles. (S<RISC OS>)
1405
e41182b5 1406=item kill LIST
1407
0a47030a 1408Not implemented, hence not useful for taint checking. (S<Mac OS>,
1409S<RISC OS>)
e41182b5 1410
0a47030a 1411Available only for process handles returned by the C<system(1, ...)>
1412method of spawning a process. (Win32)
e41182b5 1413
1414=item link OLDFILE,NEWFILE
1415
b8099c3d 1416Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
e41182b5 1417
433acd8a 1418Link count not updated because hard links are not quite that hard
1419(They are sort of half-way between hard and soft links). (AmigaOS)
1420
e41182b5 1421=item lstat FILEHANDLE
1422
1423=item lstat EXPR
1424
1425=item lstat
1426
b8099c3d 1427Not implemented. (VMS, S<RISC OS>)
e41182b5 1428
b8099c3d 1429Return values may be bogus. (Win32)
e41182b5 1430
1431=item msgctl ID,CMD,ARG
1432
1433=item msgget KEY,FLAGS
1434
1435=item msgsnd ID,MSG,FLAGS
1436
1437=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
1438
495c5fdc 1439Not implemented. (S<Mac OS>, Win32, VMS, Plan9, S<RISC OS>, VOS)
e41182b5 1440
1441=item open FILEHANDLE,EXPR
1442
1443=item open FILEHANDLE
1444
1445The C<|> variants are only supported if ToolServer is installed.
1446(S<Mac OS>)
1447
b8099c3d 1448open to C<|-> and C<-|> are unsupported. (S<Mac OS>, Win32, S<RISC OS>)
e41182b5 1449
1450=item pipe READHANDLE,WRITEHANDLE
1451
1452Not implemented. (S<Mac OS>)
1453
433acd8a 1454Very limited functionality. (MiNT)
1455
e41182b5 1456=item readlink EXPR
1457
1458=item readlink
1459
b8099c3d 1460Not implemented. (Win32, VMS, S<RISC OS>)
e41182b5 1461
1462=item select RBITS,WBITS,EBITS,TIMEOUT
1463
1464Only implemented on sockets. (Win32)
1465
b8099c3d 1466Only reliable on sockets. (S<RISC OS>)
1467
e41182b5 1468=item semctl ID,SEMNUM,CMD,ARG
1469
1470=item semget KEY,NSEMS,FLAGS
1471
1472=item semop KEY,OPSTRING
1473
495c5fdc 1474Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VOS)
e41182b5 1475
1476=item setpgrp PID,PGRP
1477
495c5fdc 1478Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VOS)
e41182b5 1479
1480=item setpriority WHICH,WHO,PRIORITY
1481
495c5fdc 1482Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VOS)
e41182b5 1483
1484=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1485
1486Not implemented. (S<Mac OS>, Plan9)
1487
1488=item shmctl ID,CMD,ARG
1489
1490=item shmget KEY,SIZE,FLAGS
1491
1492=item shmread ID,VAR,POS,SIZE
1493
1494=item shmwrite ID,STRING,POS,SIZE
1495
495c5fdc 1496Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VOS)
e41182b5 1497
1498=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1499
7c5ffed3 1500Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VOS, VM/ESA)
e41182b5 1501
1502=item stat FILEHANDLE
1503
1504=item stat EXPR
1505
1506=item stat
1507
1508mtime and atime are the same thing, and ctime is creation time instead of
1509inode change time. (S<Mac OS>)
1510
1511device and inode are not meaningful. (Win32)
1512
1513device and inode are not necessarily reliable. (VMS)
1514
b8099c3d 1515mtime, atime and ctime all return the last modification time. Device and
1516inode are not necessarily reliable. (S<RISC OS>)
1517
e41182b5 1518=item symlink OLDFILE,NEWFILE
1519
b8099c3d 1520Not implemented. (Win32, VMS, S<RISC OS>)
e41182b5 1521
1522=item syscall LIST
1523
7c5ffed3 1524Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>, VOS, VM/ESA)
e41182b5 1525
f34d0673 1526=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
1527
dd9f0070 1528The traditional "0", "1", and "2" MODEs are implemented with different
322422de 1529numeric values on some systems. The flags exported by C<Fcntl>
1530(O_RDONLY, O_WRONLY, O_RDWR) should work everywhere though. (S<Mac
7c5ffed3 1531OS>, OS/390, VM/ESA)
f34d0673 1532
e41182b5 1533=item system LIST
1534
1535Only implemented if ToolServer is installed. (S<Mac OS>)
1536
1537As an optimization, may not call the command shell specified in
1538C<$ENV{PERL5SHELL}>. C<system(1, @args)> spawns an external
1539process and immediately returns its process designator, without
1540waiting for it to terminate. Return value may be used subsequently
1541in C<wait> or C<waitpid>. (Win32)
1542
b8099c3d 1543There is no shell to process metacharacters, and the native standard is
1544to pass a command line terminated by "\n" "\r" or "\0" to the spawned
1545program. Redirection such as C<E<gt> foo> is performed (if at all) by
1546the run time library of the spawned program. C<system> I<list> will call
1547the Unix emulation library's C<exec> emulation, which attempts to provide
1548emulation of the stdin, stdout, stderr in force in the parent, providing
1549the child program uses a compatible version of the emulation library.
1550I<scalar> will call the native command line direct and no such emulation
1551of a child Unix program will exists. Mileage B<will> vary. (S<RISC OS>)
1552
433acd8a 1553Far from being POSIX compliant. Because there may be no underlying
1554/bin/sh tries to work around the problem by forking and execing the
9b63e9ec 1555first token in its argument string. Handles basic redirection
1556("E<lt>" or "E<gt>") on its own behalf. (MiNT)
433acd8a 1557
e41182b5 1558=item times
1559
1560Only the first entry returned is nonzero. (S<Mac OS>)
1561
1562"cumulative" times will be bogus. On anything other than Windows NT,
1563"system" time will be bogus, and "user" time is actually the time
1564returned by the clock() function in the C runtime library. (Win32)
1565
b8099c3d 1566Not useful. (S<RISC OS>)
1567
e41182b5 1568=item truncate FILEHANDLE,LENGTH
1569
1570=item truncate EXPR,LENGTH
1571
1572Not implemented. (VMS)
1573
495c5fdc 1574Truncation to zero-length only. (VOS)
1575
4cfdb94f 1576If a FILEHANDLE is supplied, it must be writable and opened in append
1577mode (i.e., use C<open(FH, '>>filename')>
1578or C<sysopen(FH,...,O_APPEND|O_RDWR)>. If a filename is supplied, it
1579should not be held open elsewhere. (Win32)
1580
e41182b5 1581=item umask EXPR
1582
1583=item umask
1584
1585Returns undef where unavailable, as of version 5.005.
1586
9b63e9ec 1587C<umask()> works but the correct permissions are only set when the file
1588is finally close()d. (AmigaOS)
433acd8a 1589
e41182b5 1590=item utime LIST
1591
b8099c3d 1592Only the modification time is updated. (S<Mac OS>, VMS, S<RISC OS>)
e41182b5 1593
322422de 1594May not behave as expected. Behavior depends on the C runtime
1595library's implementation of utime(), and the filesystem being
1596used. The FAT filesystem typically does not support an "access
1597time" field, and it may limit timestamps to a granularity of
1598two seconds. (Win32)
e41182b5 1599
1600=item wait
1601
1602=item waitpid PID,FLAGS
1603
495c5fdc 1604Not implemented. (S<Mac OS>, VOS)
e41182b5 1605
1606Can only be applied to process handles returned for processes spawned
1607using C<system(1, ...)>. (Win32)
1608
b8099c3d 1609Not useful. (S<RISC OS>)
1610
e41182b5 1611=back
1612
b8099c3d 1613=head1 CHANGES
1614
1615=over 4
1616
19799a22 1617=item v1.42, 22 May 1999
1618Added notes about tests, sprintf/printf, and epoch offsets.
6ab3f9cb 1619=item v1.41, 19 May 1999
1620
1621Lots more little changes to formatting and content.
1622
1623Added a bunch of <$^O> and related values
1624for various platforms; fixed mail and web addresses, and added
1625and changed miscellaneous notes. (Peter Prymmer)
1626
1627=item v1.40, 11 April 1999
1628
1629Miscellaneous changes.
1630
1631=item v1.39, 11 February 1999
2ee0eb3c 1632
1633Changes from Jarkko and EMX URL fixes Michael Schwern. Additional
1634note about newlines added.
1635
9b63e9ec 1636=item v1.38, 31 December 1998
1637
1638More changes from Jarkko.
1639
3c075c7d 1640=item v1.37, 19 December 1998
1641
1642More minor changes. Merge two separate version 1.35 documents.
1643
1644=item v1.36, 9 September 1998
1645
1646Updated for Stratus VOS. Also known as version 1.35.
1647
1648=item v1.35, 13 August 1998
495c5fdc 1649
3c075c7d 1650Integrate more minor changes, plus addition of new sections under
1651L<"ISSUES">: L<"Numbers endianness and Width">,
1652L<"Character sets and character encoding">,
1653L<"Internationalisation">.
495c5fdc 1654
3c075c7d 1655=item v1.33, 06 August 1998
0a47030a 1656
1657Integrate more minor changes.
1658
3c075c7d 1659=item v1.32, 05 August 1998
dd9f0070 1660
1661Integrate more minor changes.
1662
3c075c7d 1663=item v1.30, 03 August 1998
b8099c3d 1664
1665Major update for RISC OS, other minor changes.
1666
3c075c7d 1667=item v1.23, 10 July 1998
b8099c3d 1668
1669First public release with perl5.005.
1670
1671=back
e41182b5 1672
1673=head1 AUTHORS / CONTRIBUTORS
1674
dd9f0070 1675Abigail E<lt>abigail@fnx.comE<gt>,
bd3fa61c 1676Charles Bailey E<lt>bailey@newman.upenn.eduE<gt>,
dd9f0070 1677Graham Barr E<lt>gbarr@pobox.comE<gt>,
e41182b5 1678Tom Christiansen E<lt>tchrist@perl.comE<gt>,
dd9f0070 1679Nicholas Clark E<lt>Nicholas.Clark@liverpool.ac.ukE<gt>,
1680Andy Dougherty E<lt>doughera@lafcol.lafayette.eduE<gt>,
1681Dominic Dunlop E<lt>domo@vo.luE<gt>,
7c5ffed3 1682Neale Ferguson E<lt>neale@mailbox.tabnsw.com.auE<gt>
495c5fdc 1683Paul Green E<lt>Paul_Green@stratus.comE<gt>,
dd9f0070 1684M.J.T. Guy E<lt>mjtg@cus.cam.ac.ukE<gt>,
7c5ffed3 1685Jarkko Hietaniemi E<lt>jhi@iki.fi<gt>,
dd9f0070 1686Luther Huffman E<lt>lutherh@stratcom.comE<gt>,
1687Nick Ing-Simmons E<lt>nick@ni-s.u-net.comE<gt>,
322422de 1688Andreas J. KE<ouml>nig E<lt>koenig@kulturbox.deE<gt>,
3c075c7d 1689Markus Laker E<lt>mlaker@contax.co.ukE<gt>,
dd9f0070 1690Andrew M. Langmead E<lt>aml@world.std.comE<gt>,
19799a22 1691Larry Moore E<lt>ljmoore@freespace.netE<gt>,
e41182b5 1692Paul Moore E<lt>Paul.Moore@uk.origin-it.comE<gt>,
dd9f0070 1693Chris Nandor E<lt>pudge@pobox.comE<gt>,
322422de 1694Matthias Neeracher E<lt>neeri@iis.ee.ethz.chE<gt>,
e41182b5 1695Gary Ng E<lt>71564.1743@CompuServe.COME<gt>,
e41182b5 1696Tom Phoenix E<lt>rootbeer@teleport.comE<gt>,
dd9f0070 1697Peter Prymmer E<lt>pvhp@forte.comE<gt>,
322422de 1698Hugo van der Sanden E<lt>hv@crypt0.demon.co.ukE<gt>,
dd9f0070 1699Gurusamy Sarathy E<lt>gsar@umich.eduE<gt>,
1700Paul J. Schinder E<lt>schinder@pobox.comE<gt>,
2ee0eb3c 1701Michael G Schwern E<lt>schwern@pobox.comE<gt>,
e41182b5 1702Dan Sugalski E<lt>sugalskd@ous.eduE<gt>,
dd9f0070 1703Nathan Torkington E<lt>gnat@frii.comE<gt>.
e41182b5 1704
3c075c7d 1705This document is maintained by Chris Nandor
1706E<lt>pudge@pobox.comE<gt>.
e41182b5 1707
1708=head1 VERSION
1709
19799a22 1710Version 1.42, last modified 22 May 1999