This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
CommitLineData
e41182b5
GS
2
3perlport - Writing portable Perl
4
5
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
13perl code, so that once you have made your decision to write portably,
14you know where the lines are drawn, and you can stay within them.
15
16There is a tradeoff between taking full advantage of B<a> particular type
17of computer, and taking advantage of a full B<range> of them. Naturally,
18as you make your range bigger (and thus more diverse), the common denominators
19drop, and you are left with fewer areas of common ground in which
20you can operate to accomplish a particular task. Thus, when you begin
21attacking a problem, it is important to consider which part of the tradeoff
22curve you want to operate under. Specifically, whether it is important to
23you that the task that you are coding needs the full generality of being
24portable, or if it is sufficient to just get the job done. This is the
25hardest choice to be made. The rest is easy, because Perl provides lots
26of choices, whichever way you want to approach your problem.
27
28Looking at it another way, writing portable code is usually about willfully
29limiting your available choices. Naturally, it takes discipline to do that.
30
31Be aware of two important points:
32
33=over 4
34
35=item Not all Perl programs have to be portable
36
37There is no reason why you should not use Perl as a language to glue Unix
38tools together, or to prototype a Macintosh application, or to manage the
39Windows registry. If it makes no sense to aim for portability for one
40reason or another in a given program, then don't bother.
41
42=item The vast majority of Perl B<is> portable
43
44Don't be fooled into thinking that it is hard to create portable Perl
45code. It isn't. Perl tries its level-best to bridge the gaps between
46what's available on different platforms, and all the means available to
47use those features. Thus almost all Perl code runs on any machine
48without modification. But there I<are> some significant issues in
49writing portable code, and this document is entirely about those issues.
50
51=back
52
53Here's the general rule: When you approach a task that is commonly done
54using a whole range of platforms, think in terms of writing portable
55code. That way, you don't sacrifice much by way of the implementation
56choices you can avail yourself of, and at the same time you can give
57your users lots of platform choices. On the other hand, when you have to
58take advantage of some unique feature of a particular platform, as is
59often the case with systems programming (whether for Unix, Windows,
60S<Mac OS>, VMS, etc.), consider writing platform-specific code.
61
62When the code will run on only two or three operating systems, then you may
63only need to consider the differences of those particular systems. The
64important thing is to decide where the code will run, and to be deliberate
66
67This information should not be considered complete; it includes possibly
68transient information about idiosyncracies of some of the ports, almost
69all of which are in a state of constant evolution. Thus this material
70should be considered a perpetual work in progress
71(E<lt>IMG SRC="yellow_sign.gif" ALT="Under Construction"E<gt>).
72
73
75
77
78In most operating systems, lines in files are separated with newlines.
79Just what is used as a newline may vary from OS to OS. Unix
80traditionally uses C<\012>, one kind of Windows I/O uses C<\015\012>,
81and S<Mac OS> uses C<\015>.
82
83Perl uses C<\n> to represent the "logical" newline, where what
84is logical may depend on the platform in use. In MacPerl, C<\n>
85always means C<\015>. In DOSish perls, C<\n> usually means C<\012>, but
86when accessing a file in "text" mode, STDIO translates it to (or from)
87C<\015\012>.
88
89Due to the "text" mode translation, DOSish perls have limitations
90of using C<seek> and C<tell> when a file is being accessed in "text"
91mode. Specifically, if you stick to C<seek>-ing to locations you got
92from C<tell> (and no others), you are usually free to use C<seek> and
93C<tell> even in "text" mode. In general, using C<seek> or C<tell> or
94other file operations that count bytes instead of characters, without
95considering the length of C<\n>, may be non-portable. If you use
96C<binmode> on a file, however, you can usually use C<seek> and C<tell>
97with arbitrary values quite safely.
98
99A common misconception in socket programming is that C<\n> eq C<\012>
100everywhere. When using protocols, such as common Internet protocols,
101C<\012> and C<\015> are called for specifically, and the values of
102the logical C<\n> and C<\r> (carriage return) are not reliable.
103
104 print SOCKET "Hi there, client!\r\n"; # WRONG
105 print SOCKET "Hi there, client!\015\012"; # RIGHT
106
107[NOTE: this does not necessarily apply to communications that are
108filtered by another program or module before sending to the socket; the
109the most popular EBCDIC webserver, for instance, accepts C<\r\n>,
110which translates those characters, along with all other
111characters in text streams, from EBCDIC to ASCII.]
112
113However, C<\015\012> (or C<\cM\cJ>, or C<\x0D\x0A>) can be tedious and
114unsightly, as well as confusing to those maintaining the code. As such,
115the C<Socket> module supplies the Right Thing for those who want it.
116
117 use Socket qw(:DEFAULT :crlf);
118 print SOCKET "Hi there, client!$CRLF" # RIGHT 119 120When reading I<from> a socket, remember that the default input record 121separator (C<$/>) is C<\n>, but code like this should recognize C<$/> as 122C<\012> or C<\015\012>: 123 124 while (<SOCKET>) { 125 # ... 126 } 127 128Better: 129 130 use Socket qw(:DEFAULT :crlf); 131 local($/) = LF; # not needed if $/ is already \012 132 133 while (<SOCKET>) { 134 s/$CR?$LF/\n/; # not sure if socket uses LF or CRLF, OK 135 # s/\015?\012/\n/; # same thing 136 } 137 138And this example is actually better than the previous one even for Unix 139platforms, because now any C<\015>'s (C<\cM>'s) are stripped out 140(and there was much rejoicing). 141 142 143=head2 File Paths 144 145Most platforms these days structure files in a hierarchical fashion. 146So, it is reasonably safe to assume that any platform supports the 147notion of a "path" to uniquely identify a file on the system. Just 148how that path is actually written, differs. 149 150While they are similar, file path specifications differ between Unix, 151Windows, S<Mac OS>, OS/2, VMS and probably others. Unix, for example, is 152one of the few OSes that has the idea of a root directory. S<Mac OS> 153uses C<:> as a path separator instead of C</>. VMS, Windows, and OS/2 154can work similarly to Unix with C</> as path separator, or in their own 155idiosyncratic ways. 156 157As with the newline problem above, there are modules that can help. The 158C<File::Spec> modules provide methods to do the Right Thing on whatever 159platform happens to be running the program. 160 161 use File::Spec; 162 chdir(File::Spec->updir()); # go up one directory 163$file = File::Spec->catfile(
164 File::Spec->curdir(), 'temp', 'file.txt'
165 );
166 # on Unix and Win32, './temp/file.txt'
167 # on Mac OS, ':temp:file.txt'
168
169File::Spec is available in the standard distribution, as of version
1705.004_05.
171
172In general, production code should not have file paths hardcoded; making
173them user supplied or from a configuration file is better, keeping in mind
174that file path syntax varies on different machines.
175
176This is especially noticeable in scripts like Makefiles and test suites,
177which often assume C</> as a path separator for subdirectories.
178
179Also of use is C<File::Basename>, from the standard distribution, which
180splits a pathname into pieces (base filename, full path to directory,
181and file suffix).
182
183Remember not to count on the existence of system-specific files, like
184F</etc/resolv.conf>. If code does need to rely on such a file, include a
185description of the file and its format in the code's documentation, and
186make it easy for the user to override the default location of the file.
187
188
190
191Not all platforms provide for the notion of a command line, necessarily.
192These are usually platforms that rely on a Graphical User Interface (GUI)
193for user interaction. So a program requiring command lines might not work
194everywhere. But this is probably for the user of the program to deal
195with.
196
197Some platforms can't delete or rename files that are being held open by
198the system. Remember to C<close> files when you are done with them.
199Don't C<unlink> or C<rename> an open file. Don't C<tie> to or C<open> a
200file that is already tied to or opened; C<untie> or C<close> first.
201
202Don't count on a specific environment variable existing in C<%ENV>.
203Don't even count on C<%ENV> entries being case-sensitive, or even
204case-preserving.
205
206Don't count on signals in portable programs.
207
208Don't count on filename globbing. Use C<opendir>, C<readdir>, and
210
211
213
214In general, don't directly access the system in code that is meant to be
215portable. That means, no: C<system>, C<exec>, C<fork>, C<pipe>, C<>,
216C<qx//>, C<open> with a C<|>, or any of the other things that makes being
217a Unix perl hacker worth being.
218
219Commands that launch external processes are generally supported on
220most platforms (though many of them do not support any type of forking),
221but the problem with using them arises from what you invoke with them.
222External tools are often named differently on different platforms, often
223not available in the same location, often accept different arguments,
224often behave differently, and often represent their results in a
225platform-dependent way. Thus you should seldom depend on them to produce
226consistent results.
227
228One especially common bit of Perl code is opening a pipe to sendmail:
229
230 open(MAIL, '|/usr/lib/sendmail -t') or die $!; 231 232This is fine for systems programming when sendmail is known to be 233available. But it is not fine for many non-Unix systems, and even 234some Unix systems that may not have sendmail installed. If a portable 235solution is needed, see the C<Mail::Send> and C<Mail::Mailer> modules 236in the C<MailTools> distribution. C<Mail::Mailer> provides several 237mailing methods, including mail, sendmail, and direct SMTP 238(via C<Net::SMTP>) if a mail transfer agent is not available. 239 240The rule of thumb for portable code is: Do it all in portable Perl, or 241use a module that may internally implement it with platform-specific code, 242but expose a common interface. By portable Perl, we mean code that 243avoids the constructs described in this document as being non-portable. 244 245 246=head2 External Subroutines (XS) 247 248XS code, in general, can be made to work with any platform; but dependent 249libraries, header files, etc., might not be readily available or 250portable, or the XS code itself might be platform-specific, just as Perl 251code might be. If the libraries and headers are portable, then it is 252normally reasonable to make sure the XS code is portable, too. 253 254There is a different kind of portability issue with writing XS 255code: availability of a C compiler on the end-user's system. C brings with 256it its own portability issues, and writing XS code will expose you to 257some of those. Writing purely in perl is a comparatively easier way to 258achieve portability. 259 260 261=head2 Standard Modules 262 263In general, the standard modules work across platforms. Notable 264exceptions are C<CPAN.pm> (which currently makes connections to external 265programs that may not be available), platform-specific modules (like 266C<ExtUtils::MM_VMS>), and DBM modules. 267 268There is no one DBM module that is available on all platforms. 269C<SDBM_File> and the others are generally available on all Unix and DOSish 270ports, but not in MacPerl, where C<NBDM_File> and C<DB_File> are available. 271 272The good news is that at least some DBM module should be available, and 273C<AnyDBM_File> will use whichever module it can find. Of course, then 274the code needs to be fairly strict, dropping to the lowest common 275denominator (e.g., not exceeding 1K for each record). 276 277 278=head2 Time and Date 279 280The system's notion of time of day and calendar date is controlled in widely 281different ways. Don't assume the timezone is stored in C<$ENV{TZ}>, and even
282if it is, don't assume that you can control the timezone through that
283variable.
284
285Don't assume that the epoch starts at January 1, 1970, because that is
286OS-specific. Better to store a date in an unambiguous representation.
287A text representation (like C<1 Jan 1970>) can be easily converted into an
288OS-specific value using a module like C<Date::Parse>. An array of values,
289such as those returned by C<localtime>, can be converted to an OS-specific
290representation using C<Time::Local>.
291
292
294
295If your code is destined for systems with severely constrained (or missing!)
296virtual memory systems then you want to be especially mindful of avoiding
297wasteful constructs such as:
298
299 # NOTE: this is no longer "bad" in perl5.005
300 for (0..10000000) {} # bad
301 for (my $x = 0;$x <= 10000000; ++$x) {} # good 302 303 @lines = <VERY_LARGE_FILE>; # bad 304 305 while (<FILE>) {$file .= $_} # sometimes bad 306$file = join '', <FILE>; # better
307
308The last two may appear unintuitive to most people. The first of those
309two constructs repeatedly grows a string, while the second allocates a
310large chunk of memory in one go. On some systems, the latter is more
311efficient that the former.
312
314
315Most Unix platforms provide basic levels of security that is usually felt
316at the file-system level. Other platforms usually don't (unfortunately).
317Thus the notion of User-ID, or "home" directory, or even the state of
318being logged-in may be unrecognizable on may platforms. If you write
319programs that are security conscious, it is usually best to know what
320type of system you will be operating under, and write code explicitly
321for that platform (or class of platforms).
322
324
325For those times when it is necessary to have platform-specific code,
326consider keeping the platform-specific code in one place, making porting
327to other platforms easier. Use the C<Config> module and the special
328variable C<$^O> to differentiate platforms, as described in L<"PLATFORMS">. 329 330 331=head1 CPAN TESTERS 332 333Module uploaded to CPAN are tested by a variety of volunteers on 334different platforms. These CPAN testers are notified by e-mail of each 335new upload, and reply to the list with PASS, FAIL, NA (not applicable to 336this platform), or ???? (unknown), along with any relevant notations. 337 338The purpose of the testing is twofold: one, to help developers fix any 339problems in their code; two, to provide users with information about 340whether or not a given module works on a given platform. 341 342=over 4 343 344=item Mailing list: cpan-testers@perl.org 345 346=item Testing results: C<http://www.connect.net/gbarr/cpan-test/> 347 348=back 349 350 351=head1 PLATFORMS 352 353As of version 5.002, Perl is built with a C<$^O> variable that
354indicates the operating system it was built on. This was implemented
355to help speed up code that would otherwise have to C<use Config;> and
356use the value of C<$Config{'osname'}>. Of course, to get 357detailed information about the system, looking into C<%Config> is 358certainly recommended. 359 360=head2 Unix 361 362Perl works on a bewildering variety of Unix and Unix-like platforms (see 363e.g. most of the files in the F<hints/> directory in the source code kit). 364On most of these systems, the value of C<$^O> (hence C<$Config{'osname'}>, 365too) is determined by lowercasing and stripping punctuation from the first 366field of the string returned by typing 367 368 % uname -a 369 370(or a similar command) at the shell prompt. Here, for example, are a few 371of the more popular Unix flavors: 372 373 uname$^O
374 --------------------
375 AIX aix
376 FreeBSD freebsd
377 Linux linux
378 HP-UX hpux
379 OSF1 dec_osf
380 SunOS solaris
381 SunOS4 sunos
382
383
385
386Perl has long been ported to PC style microcomputers running under
387systems like PC-DOS, MS-DOS, OS/2, and most Windows platforms you can
388bring yourself to mention (except for Windows CE, if you count that).
389Users familiar with I<COMMAND.COM> and/or I<CMD.EXE> style shells should
390be aware that each of these file specifications may have subtle
391differences:
392
393 $filespec0 = "c:/foo/bar/file.txt"; 394$filespec1 = "c:\\foo\\bar\\file.txt";
395 $filespec2 = 'c:\foo\bar\file.txt'; 396$filespec3 = 'c:\\foo\\bar\\file.txt';
397
398System calls accept either C</> or C<\> as the path separator. However,
399many command-line utilities of DOS vintage treat C</> as the option
400prefix, so they may get confused by filenames containing C</>. Aside
401from calling any external programs, C</> will work just fine, and
402probably better, as it is more consistent with popular usage, and avoids
403the problem of remembering what to backwhack and what not to.
404
405The DOS FAT file system can only accomodate "8.3" style filenames. Under
406the "case insensitive, but case preserving" HPFS (OS/2) and NTFS (NT)
407file systems you may have to be careful about case returned with functions
408like C<readdir> or used with functions like C<open> or C<opendir>.
409
410DOS also treats several filenames as special, such as AUX, PRN, NUL, CON,
411COM1, LPT1, LPT2 etc. Unfortunately these filenames won't even work
412if you include an explicit directory prefix, in some cases. It is best
413to avoid such filenames, if you want your code to be portable to DOS
414and its derivatives.
415
416Users of these operating systems may also wish to make use of
417scripts such as I<pl2bat.bat> or I<pl2cmd> as appropriate to
419
420Newline (C<\n>) is translated as C<\015\012> by STDIO when reading from
421and writing to files. C<binmode(FILEHANDLE)> will keep C<\n> translated
422as C<\012> for that filehandle. Since it is a noop on other systems,
423C<binmode> should be used for cross-platform code that deals with binary
424data.
425
426The C<$^O> variable and the C<$Config{'archname'}> values for various
427DOSish perls are as follows:
428
429 OS $^O$Config{'archname'}
430 --------------------------------------------
431 MS-DOS dos
432 PC-DOS dos
433 OS/2 os2
434 Windows 95 MSWin32 MSWin32-x86
435 Windows NT MSWin32 MSWin32-x86
436 Windows NT MSWin32 MSWin32-alpha
437 Windows NT MSWin32 MSWin32-ppc
438
439Also see:
440
441=over 4
442
443=item The djgpp environment for DOS, C<http://www.delorie.com/djgpp/>
444
445=item The EMX environment for DOS, OS/2, etc. C<emx@iaehv.nl>,
446C<http://www.juge.com/bbs/Hobb.19.html>
447
448=item Build instructions for Win32, L<perlwin32>.
449
450=item The ActiveState Pages, C<http://www.activestate.com/>
451
452=back
453
454
456
457Any module requiring XS compilation is right out for most people, because
458MacPerl is built using non-free (and non-cheap!) compilers. Some XS
459modules that can work with MacPerl are built and distributed in binary
460form on CPAN. See I<MacPerl: Power and Ease> for more details.
461
462Directories are specified as:
463
464 volume:folder:file for absolute pathnames
465 volume:folder: for absolute pathnames
466 :folder:file for relative pathnames
467 :folder: for relative pathnames
468 :file for relative pathnames
469 file for relative pathnames
470
471Files in a directory are stored in alphabetical order. Filenames are
472limited to 31 characters, and may include any character except C<:>,
473which is reserved as a path separator.
474
475Instead of C<flock>, see C<FSpSetFLock> and C<FSpRstFLock> in
476C<Mac::Files>.
477
478In the MacPerl application, you can't run a program from the command line;
479programs that expect C<@ARGV> to be populated can be edited with something
480like the following, which brings up a dialog box asking for the command
481line arguments.
482
483 if (!@ARGV) {
484 @ARGV = split /\s+/, MacPerl::Ask('Arguments?');
485 }
486
487A MacPerl script saved as a droplet will populate C<@ARGV> with the full
488pathnames of the files dropped onto the script.
489
490Mac users can use programs on a kind of command line under MPW (Macintosh
491Programmer's Workshop, a free development environment from Apple).
492MacPerl was first introduced as an MPW tool, and MPW can be used like a
493shell:
494
495 perl myscript.plx some arguments
496
497ToolServer is another app from Apple that provides access to MPW tools
498from MPW and the MacPerl app, which allows MacPerl program to use
499C<system>, backticks, and piped C<open>.
500
501"S<Mac OS>" is the proper name for the operating system, but the value
502in C<$^O> is "MacOS". To determine architecture, version, or whether 503the application or MPW tool version is running, check: 504 505$is_app = $MacPerl::Version =~ /App/; 506$is_tool = $MacPerl::Version =~ /MPW/; 507 ($version) = $MacPerl::Version =~ /^(\S+)/; 508$is_ppc = $MacPerl::Architecture eq 'MacPPC'; 509$is_68k = $MacPerl::Architecture eq 'Mac68K'; 510 511 512Also see: 513 514=over 4 515 516=item The MacPerl Pages, C<http://www.ptf.com/macperl/>. 517 518=item The MacPerl mailing list, C<mac-perl-request@iis.ee.ethz.ch>. 519 520=back 521 522 523=head2 VMS 524 525Perl on VMS is discussed in F<vms/perlvms.pod> in the perl distribution. 526Note that perl on VMS can accept either VMS or Unix style file 527specifications as in either of the following: 528 529$ perl -ne "print if /perl_setup/i" SYS$LOGIN:LOGIN.COM 530$ perl -ne "print if /perl_setup/i" /sys$login/login.com 531 532but not a mixture of both as in: 533 534$ perl -ne "print if /perl_setup/i" sys$login:/login.com 535 Can't open sys$login:/login.com: file specification syntax error
536
537Interacting with Perl from the Digital Command Language (DCL) shell
538often requires a different set of quotation marks than Unix shells do.
539For example:
540
541 $perl -e "print ""Hello, world.\n""" 542 Hello, world. 543 544There are a number of ways to wrap your perl scripts in DCL .COM files if 545you are so inclined. For example: 546 547$ write sys$output "Hello from DCL!" 548$ if p1 .eqs. ""
549 $then perl -x 'f$environment("PROCEDURE")
550 $else perl -x - 'p1 'p2 'p3 'p4 'p5 'p6 'p7 'p8 551$ deck/dollars="__END__"
552 #!/usr/bin/perl
553
554 print "Hello from Perl!\n";
555
556 __END__
557 $endif 558 559Do take care with C<$ ASSIGN/nolog/user SYS$COMMAND: SYS$INPUT> if your
560perl-in-DCL script expects to do things like C<$read = E<lt>STDINE<gt>;>. 561 562Filenames are in the format "name.extension;version". The maximum 563length for filenames is 39 characters, and the maximum length for 564extensions is also 39 characters. Version is a number from 1 to 56532767. Valid characters are C</[A-Z0-9$_-]/>.
566
567VMS' RMS filesystem is case insensitive and does not preserve case.
568C<readdir> returns lowercased filenames, but specifying a file for
569opening remains case insensitive. Files without extensions have a
570trailing period on them, so doing a C<readdir> with a file named F<A.;5>
571will return F<a.> (though that file could be opened with C<open(FH, 'A')>.
572
573RMS has an eight level limit on directory depths from any rooted logical
574(allowing 16 levels overall). Hence C<PERL_ROOT:[LIB.2.3.4.5.6.7.8]>
575is a valid directory specification but C<PERL_ROOT:[LIB.2.3.4.5.6.7.8.9]>
576is not. F<Makefile.PL> authors might have to take this into account, but
577at least they can refer to the former as C</PERL_ROOT/lib/2/3/4/5/6/7/8/>.
578
579The C<VMS::Filespec> module, which gets installed as part
580of the build process on VMS, is a pure Perl module that can easily be
581installed on non-VMS platforms and can be helpful for conversions to
582and from RMS native formats.
583
584What C<\n> represents depends on the type of file that is open. It could
585be C<\015>, C<\012>, C<\015\012>, or nothing. Reading from a file
586translates newlines to C<\012>, unless C<binmode> was executed on that
587handle, just like DOSish perls.
588
589TCP/IP stacks are optional on VMS, so socket routines might not be
590implemented. UDP sockets may not be supported.
591
592The value of C<$^O> on OpenVMS is "VMS". To determine the architecture 593that you are running on without resorting to loading all of C<%Config> 594you can examine the content of the C<@INC> array like so: 595 596 if (grep(/VMS_AXP/, @INC)) { 597 print "I'm on Alpha!\n"; 598 } elsif (grep(/VMS_VAX/, @INC)) { 599 print "I'm on VAX!\n"; 600 } else { 601 print "I'm not so sure about where$^O is...\n";
602 }
603
604Also see:
605
606=over 4
607
608=item L<perlvms.pod>
609
610=item vmsperl list, C<vmsperl-request@newman.upenn.edu>
611
612Put words C<SUBSCRIBE VMSPERL> in message body.
613
614=item vmsperl on the web, C<http://www.sidhe.org/vmsperl/index.html>
615
616=back
617
618
620
621Recent versions of Perl have been ported to platforms such as OS/400 on
622AS/400 minicomputers as well as OS/390 for IBM Mainframes. Such computers
623use EBCDIC character sets internally (usually Character Code Set ID 00819
624for OS/400 and IBM-1047 for OS/390). Note that on the mainframe perl
625currently works under the "Unix system services for OS/390" (formerly
626known as OpenEdition).
627
628As of R2.5 of USS for OS/390 that Unix sub-system did not support the
629C<#!> shebang trick for script invocation. Hence, on OS/390 perl scripts
630can executed with a header similar to the following simple script:
631
632 : # use perl
633 eval 'exec /usr/local/bin/perl -S $0${1+"$@"}' 634 if 0; 635 #!/usr/local/bin/perl # just a comment really 636 637 print "Hello from perl!\n"; 638 639On these platforms, bear in mind that the EBCDIC character set may have 640an effect on what happens with perl functions such as C<chr>, C<pack>, 641C<print>, C<printf>, C<ord>, C<sort>, C<sprintf>, C<unpack>; as well as 642bit-fiddling with ASCII constants using operators like C<^>, C<&> and 643C<|>; not to mention dealing with socket interfaces to ASCII computers 644(see L<"NEWLINES">). 645 646Fortunately, most web servers for the mainframe will correctly translate 647the C<\n> in the following statement to its ASCII equivalent (note that 648C<\r> is the same under both ASCII and EBCDIC): 649 650 print "Content-type: text/html\r\n\r\n"; 651 652The value of C<$^O> on OS/390 is "os390".
653
654Some simple tricks for determining if you are running on an EBCDIC
655platform could include any of the following (perhaps all):
656
657 if ("\t" eq "\05") { print "EBCDIC may be spoken here!\n"; }
658
659 if (ord('A') == 193) { print "EBCDIC may be spoken here!\n"; }
660
661 if (chr(169) eq 'z') { print "EBCDIC may be spoken here!\n"; }
662
663Note that one thing you may not want to rely on is the EBCDIC encoding
664of punctuation characters since these may differ from code page to code page
665(and once your module or script is rumoured to work with EBCDIC, folks will
666want it to work with all EBCDIC character sets).
667
668Also see:
669
670=over 4
671
672=item perl-mvs list
673
674The perl-mvs@perl.org list is for discussion of porting issues as well as
675general usage issues for all EBCDIC Perls. Send a message body of
676"subscribe perl-mvs" to majordomo@perl.org.
677
678=item AS/400 Perl information at C<http://as400.rochester.ibm.com>
679
680=back
681
683
684Perl has been ported to a variety of platforms that do not fit into any of
685the above categories. Some, such as AmigaOS, BeOS, QNX, and Plan 9, have
686been well integrated into the standard Perl source code kit. You may need
687to see the F<ports/> directory on CPAN for information, and possibly
688binaries, for the likes of: acorn, aos, atari, lynxos, HP-MPE/iX, riscos,
689Tandem Guardian, vos, I<etc.> (yes we know that some of these OSes may fall
690under the Unix category but we are not a standards body.)
691
693
694=over 4
695
696=item Atari, Guido Flohr's page C<http://stud.uni-sb.de/~gufl0000/>
697
698=item HP 300 MPE/iX C<http://www.cccd.edu/~markb/perlix.html>
699
700=item Novell Netware
701
702A free Perl 5 based PERL.NLM for Novell Netware is available from
703C<http://www.novell.com/>
704
705=back
706
707
709
710Listed below are functions unimplemented or implemented differently on
711various platforms. Following each description will be, in parentheses, a
712list of platforms that the description applies to.
713
714The list may very well be incomplete, or wrong in some places. When in
715doubt, consult the platform-specific README files in the Perl source
716distribution, and other documentation resources for a given port.
717
718Be aware, moreover, that even among Unix-ish systems there are variations,
719and not all functions listed here are necessarily available, though
720most usually are.
721
722For many functions, you can also query C<%Config>, exported by default
723from C<Config.pm>. For example, to check if the platform has the C<lstat>
724call, check C<$Config{'d_lstat'}>. See L<Config> for a full description 725of available variables. 726 727 728=head2 Alphabetical Listing of Perl Functions 729 730=over 8 731 732=item -X FILEHANDLE 733 734=item -X EXPR 735 736=item -X 737 738C<-r>, C<-w>, and C<-x> have only a very limited meaning; directories 739and applications are executable, and there are no uid/gid 740considerations. C<-o> is not supported. (S<Mac OS>) 741 742C<-r>, C<-w>, C<-x>, and C<-o> tell whether or not file is accessible, 743which may not reflect UIC-based file protections. (VMS) 744 745C<-R>, C<-W>, C<-X>, C<-O> are indistinguishable from C<-r>, C<-w>, 746C<-x>, C<-o>. (S<Mac OS>, Win32, VMS) 747 748C<-b>, C<-c>, C<-k>, C<-g>, C<-p>, C<-u>, C<-A> are not implemented. 749(S<Mac OS>) 750 751C<-g>, C<-k>, C<-l>, C<-p>, C<-u>, C<-A> are not particularly meaningful. 752(Win32, VMS) 753 754C<-d> is true if passed a device spec without an explicit directory. 755(VMS) 756 757C<-T> and C<-B> are implemented, but might misclassify Mac text files 758with foreign characters; this is the case will all platforms, but 759affects S<Mac OS> a lot. (S<Mac OS>) 760 761C<-x> (or C<-X>) determine if a file ends in one of the executable 762suffixes. C<-S> is meaningless. (Win32) 763 764=item binmode FILEHANDLE 765 766Meaningless. (S<Mac OS>) 767 768Reopens file and restores pointer; if function fails, underlying 769filehandle may be closed, or pointer may be in a different position. 770(VMS) 771 772The value returned by C<tell> may be affected after the call, and 773the filehandle may be flushed. (Win32) 774 775=item chmod LIST 776 777Only limited meaning. Disabling/enabling write permission is mapped to 778locking/unlocking the file. (S<Mac OS>) 779 780Only good for changing "owner" read-write access, "group", and "other" 781bits are meaningless. (Win32) 782 783=item chown LIST 784 785Not implemented. (S<Mac OS>, Win32, Plan9) 786 787Does nothing, but won't fail. (Win32) 788 789=item chroot FILENAME 790 791=item chroot 792 793Not implemented. (S<Mac OS>, Win32, VMS, Plan9) 794 795=item crypt PLAINTEXT,SALT 796 797May not be available if library or source was not provided when building 798perl. (Win32) 799 800=item dbmclose HASH 801 802Not implemented. (VMS, Plan9) 803 804=item dbmopen HASH,DBNAME,MODE 805 806Not implemented. (VMS, Plan9) 807 808=item dump LABEL 809 810Not useful. (S<Mac OS>) 811 812Not implemented. (Win32) 813 814Invokes VMS debugger. (VMS) 815 816=item exec LIST 817 818Not implemented. (S<Mac OS>) 819 820=item fcntl FILEHANDLE,FUNCTION,SCALAR 821 822Not implemented. (Win32, VMS) 823 824=item flock FILEHANDLE,OPERATION 825 826Not implemented (S<Mac OS>, VMS). 827 828Available only on Windows NT (not on Windows 95). (Win32) 829 830=item fork 831 832Not implemented. (S<Mac OS>, Win32, AmigaOS) 833 834=item getlogin 835 836Not implemented. (S<Mac OS>) 837 838=item getpgrp PID 839 840Not implemented. (S<Mac OS>, Win32, VMS) 841 842=item getppid 843 844Not implemented. (S<Mac OS>, Win32, VMS) 845 846=item getpriority WHICH,WHO 847 848Not implemented. (S<Mac OS>, Win32, VMS) 849 850=item getpwnam NAME 851 852Not implemented. (S<Mac OS>, Win32) 853 854=item getgrnam NAME 855 856Not implemented. (S<Mac OS>, Win32, VMS) 857 858=item getnetbyname NAME 859 860Not implemented. (S<Mac OS>, Win32, Plan9) 861 862=item getpwuid UID 863 864Not implemented. (S<Mac OS>, Win32) 865 866=item getgrgid GID 867 868Not implemented. (S<Mac OS>, Win32, VMS) 869 870=item getnetbyaddr ADDR,ADDRTYPE 871 872Not implemented. (S<Mac OS>, Win32, Plan9) 873 874=item getprotobynumber NUMBER 875 876Not implemented. (S<Mac OS>) 877 878=item getservbyport PORT,PROTO 879 880Not implemented. (S<Mac OS>) 881 882=item getpwent 883 884Not implemented. (S<Mac OS>, Win32) 885 886=item getgrent 887 888Not implemented. (S<Mac OS>, Win32, VMS) 889 890=item gethostent 891 892Not implemented. (S<Mac OS>, Win32) 893 894=item getnetent 895 896Not implemented. (S<Mac OS>, Win32, Plan9) 897 898=item getprotoent 899 900Not implemented. (S<Mac OS>, Win32, Plan9) 901 902=item getservent 903 904Not implemented. (Win32, Plan9) 905 906=item setpwent 907 908Not implemented. (S<Mac OS>, Win32) 909 910=item setgrent 911 912Not implemented. (S<Mac OS>, Win32, VMS) 913 914=item sethostent STAYOPEN 915 916Not implemented. (S<Mac OS>, Win32, Plan9) 917 918=item setnetent STAYOPEN 919 920Not implemented. (S<Mac OS>, Win32, Plan9) 921 922=item setprotoent STAYOPEN 923 924Not implemented. (S<Mac OS>, Win32, Plan9) 925 926=item setservent STAYOPEN 927 928Not implemented. (Plan9, Win32) 929 930=item endpwent 931 932Not implemented. (S<Mac OS>, Win32) 933 934=item endgrent 935 936Not implemented. (S<Mac OS>, Win32, VMS) 937 938=item endhostent 939 940Not implemented. (S<Mac OS>, Win32) 941 942=item endnetent 943 944Not implemented. (S<Mac OS>, Win32, Plan9) 945 946=item endprotoent 947 948Not implemented. (S<Mac OS>, Win32, Plan9) 949 950=item endservent 951 952Not implemented. (Plan9, Win32) 953 954=item getsockopt SOCKET,LEVEL,OPTNAME 955 956Not implemented. (S<Mac OS>, Plan9) 957 958=item glob EXPR 959 960=item glob 961 962Globbing built-in, but only C<*> and C<?> metacharacters are supported. 963(S<Mac OS>) 964 965Features depend on external perlglob.exe or perlglob.bat. May be overridden 966with something like File::DosGlob, which is recommended. (Win32) 967 968=item ioctl FILEHANDLE,FUNCTION,SCALAR 969 970Not implemented. (VMS) 971 972Available only for socket handles, and it does what the ioctlsocket() call 973in the Winsock API does. (Win32) 974 975=item kill LIST 976 977Not implemented. (S<Mac OS>) 978 979Available only for process handles returned by the C<system(1, ...)> method of 980spawning a process. (Win32) 981 982=item link OLDFILE,NEWFILE 983 984Not implemented. (S<Mac OS>, Win32, VMS) 985 986=item lstat FILEHANDLE 987 988=item lstat EXPR 989 990=item lstat 991 992Not implemented. (VMS) 993 994Return values may be bogus. (Win32) 995 996=item msgctl ID,CMD,ARG 997 998=item msgget KEY,FLAGS 999 1000=item msgsnd ID,MSG,FLAGS 1001 1002=item msgrcv ID,VAR,SIZE,TYPE,FLAGS 1003 1004Not implemented. (S<Mac OS>, Win32, VMS, Plan9) 1005 1006=item open FILEHANDLE,EXPR 1007 1008=item open FILEHANDLE 1009 1010The C<|> variants are only supported if ToolServer is installed. 1011(S<Mac OS>) 1012 1013open to C<|-> and C<-|> are unsupported. (S<Mac OS>, Win32) 1014 1015=item pipe READHANDLE,WRITEHANDLE 1016 1017Not implemented. (S<Mac OS>) 1018 1019=item readlink EXPR 1020 1021=item readlink 1022 1023Not implemented. (Win32, VMS) 1024 1025=item select RBITS,WBITS,EBITS,TIMEOUT 1026 1027Only implemented on sockets. (Win32) 1028 1029=item semctl ID,SEMNUM,CMD,ARG 1030 1031=item semget KEY,NSEMS,FLAGS 1032 1033=item semop KEY,OPSTRING 1034 1035Not implemented. (S<Mac OS>, Win32, VMS) 1036 1037=item setpgrp PID,PGRP 1038 1039Not implemented. (S<Mac OS>, Win32, VMS) 1040 1041=item setpriority WHICH,WHO,PRIORITY 1042 1043Not implemented. (S<Mac OS>, Win32, VMS) 1044 1045=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL 1046 1047Not implemented. (S<Mac OS>, Plan9) 1048 1049=item shmctl ID,CMD,ARG 1050 1051=item shmget KEY,SIZE,FLAGS 1052 1053=item shmread ID,VAR,POS,SIZE 1054 1055=item shmwrite ID,STRING,POS,SIZE 1056 1057Not implemented. (S<Mac OS>, Win32, VMS) 1058 1059=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL 1060 1061Not implemented. (S<Mac OS>, Win32, VMS) 1062 1063=item stat FILEHANDLE 1064 1065=item stat EXPR 1066 1067=item stat 1068 1069mtime and atime are the same thing, and ctime is creation time instead of 1070inode change time. (S<Mac OS>) 1071 1072device and inode are not meaningful. (Win32) 1073 1074device and inode are not necessarily reliable. (VMS) 1075 1076=item symlink OLDFILE,NEWFILE 1077 1078Not implemented. (Win32, VMS) 1079 1080=item syscall LIST 1081 1082Not implemented. (S<Mac OS>, Win32, VMS) 1083 1084=item system LIST 1085 1086Only implemented if ToolServer is installed. (S<Mac OS>) 1087 1088As an optimization, may not call the command shell specified in 1089C<$ENV{PERL5SHELL}>. C<system(1, @args)> spawns an external
1090process and immediately returns its process designator, without
1091waiting for it to terminate. Return value may be used subsequently
1092in C<wait> or C<waitpid>. (Win32)
1093
1094=item times
1095
1096Only the first entry returned is nonzero. (S<Mac OS>)
1097
1098"cumulative" times will be bogus. On anything other than Windows NT,
1099"system" time will be bogus, and "user" time is actually the time
1100returned by the clock() function in the C runtime library. (Win32)
1101
1102=item truncate FILEHANDLE,LENGTH
1103
1104=item truncate EXPR,LENGTH
1105
1106Not implemented. (VMS)
1107
1109
1111
1112Returns undef where unavailable, as of version 5.005.
1113
1114=item utime LIST
1115
1116Only the modification time is updated. (S<Mac OS>, VMS)
1117
1118May not behave as expected. (Win32)
1119
1120=item wait
1121
1122=item waitpid PID,FLAGS
1123
1124Not implemented. (S<Mac OS>)
1125
1126Can only be applied to process handles returned for processes spawned
1127using C<system(1, ...)>. (Win32)
1128
1129=back
1130
1131
1133
1134Chris Nandor E<lt>pudge@pobox.comE<gt>,
1135Gurusamy Sarathy E<lt>gsar@umich.eduE<gt>,
1136Peter Prymmer E<lt>pvhp@forte.comE<gt>,
1137Tom Christiansen E<lt>tchrist@perl.comE<gt>,
1138Nathan Torkington E<lt>gnat@frii.comE<gt>,
1139Paul Moore E<lt>Paul.Moore@uk.origin-it.comE<gt>,
1140Matthias Neercher E<lt>neeri@iis.ee.ethz.chE<gt>,
1141Charles Bailey E<lt>bailey@genetics.upenn.eduE<gt>,
1142Luther Huffman E<lt>lutherh@stratcom.comE<gt>,
1143Gary Ng E<lt>71564.1743@CompuServe.COME<gt>,
1144Nick Ing-Simmons E<lt>nick@ni-s.u-net.comE<gt>,
1145Paul J. Schinder E<lt>schinder@pobox.comE<gt>,
1146Tom Phoenix E<lt>rootbeer@teleport.comE<gt>,
1147Hugo van der Sanden E<lt>h.sanden@elsevier.nlE<gt>,
1148Dominic Dunlop E<lt>domo@vo.luE<gt>,
1149Dan Sugalski E<lt>sugalskd@ous.eduE<gt>,
1150Andreas J. Koenig E<lt>koenig@kulturbox.deE<gt>,