update postscript generator
[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
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
65in your decision.
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
74=head1 ISSUES
75
76=head2 Newlines
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
189=head2 System Interaction
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
209C<closedir> instead.
210
211
212=head2 Interprocess Communication (IPC)
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
293=head2 System Resources
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
313=head2 Security
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
323=head2 Style
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
384=head2 DOS and Derivatives
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
418put wrappers around your scripts.
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
455=head2 MacPerl
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
619=head2 EBCDIC Platforms
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
682=head2 Other perls
683
9d116dd7 684Perl has been ported to a variety of platforms that do not fit into
685any of the above categories. Some, such as AmigaOS, BeOS, MPE/iX,
686OS/390 (MVS), QNX, and Plan 9, have been well integrated into the
687standard Perl source code kit. You may need to see the F<ports/>
688directory on CPAN for information, and possibly binaries, for the
689likes of: acorn, aos, atari, lynxos, riscos, Tandem Guardian, vos,
690I<etc.> (yes we know that some of these OSes may fall under the Unix
691category but we are not a standards body.)
e41182b5 692
693See also:
694
695=over 4
696
697=item Atari, Guido Flohr's page C<http://stud.uni-sb.de/~gufl0000/>
698
699=item HP 300 MPE/iX C<http://www.cccd.edu/~markb/perlix.html>
700
701=item Novell Netware
702
703A free Perl 5 based PERL.NLM for Novell Netware is available from
704C<http://www.novell.com/>
705
706=back
707
708
709=head1 FUNCTION IMPLEMENTATIONS
710
711Listed below are functions unimplemented or implemented differently on
712various platforms. Following each description will be, in parentheses, a
713list of platforms that the description applies to.
714
715The list may very well be incomplete, or wrong in some places. When in
716doubt, consult the platform-specific README files in the Perl source
717distribution, and other documentation resources for a given port.
718
719Be aware, moreover, that even among Unix-ish systems there are variations,
720and not all functions listed here are necessarily available, though
721most usually are.
722
723For many functions, you can also query C<%Config>, exported by default
724from C<Config.pm>. For example, to check if the platform has the C<lstat>
725call, check C<$Config{'d_lstat'}>. See L<Config> for a full description
726of available variables.
727
728
729=head2 Alphabetical Listing of Perl Functions
730
731=over 8
732
733=item -X FILEHANDLE
734
735=item -X EXPR
736
737=item -X
738
739C<-r>, C<-w>, and C<-x> have only a very limited meaning; directories
740and applications are executable, and there are no uid/gid
741considerations. C<-o> is not supported. (S<Mac OS>)
742
743C<-r>, C<-w>, C<-x>, and C<-o> tell whether or not file is accessible,
744which may not reflect UIC-based file protections. (VMS)
745
746C<-R>, C<-W>, C<-X>, C<-O> are indistinguishable from C<-r>, C<-w>,
747C<-x>, C<-o>. (S<Mac OS>, Win32, VMS)
748
749C<-b>, C<-c>, C<-k>, C<-g>, C<-p>, C<-u>, C<-A> are not implemented.
750(S<Mac OS>)
751
752C<-g>, C<-k>, C<-l>, C<-p>, C<-u>, C<-A> are not particularly meaningful.
753(Win32, VMS)
754
755C<-d> is true if passed a device spec without an explicit directory.
756(VMS)
757
758C<-T> and C<-B> are implemented, but might misclassify Mac text files
759with foreign characters; this is the case will all platforms, but
760affects S<Mac OS> a lot. (S<Mac OS>)
761
762C<-x> (or C<-X>) determine if a file ends in one of the executable
763suffixes. C<-S> is meaningless. (Win32)
764
765=item binmode FILEHANDLE
766
767Meaningless. (S<Mac OS>)
768
769Reopens file and restores pointer; if function fails, underlying
770filehandle may be closed, or pointer may be in a different position.
771(VMS)
772
773The value returned by C<tell> may be affected after the call, and
774the filehandle may be flushed. (Win32)
775
776=item chmod LIST
777
778Only limited meaning. Disabling/enabling write permission is mapped to
779locking/unlocking the file. (S<Mac OS>)
780
781Only good for changing "owner" read-write access, "group", and "other"
782bits are meaningless. (Win32)
783
784=item chown LIST
785
786Not implemented. (S<Mac OS>, Win32, Plan9)
787
788Does nothing, but won't fail. (Win32)
789
790=item chroot FILENAME
791
792=item chroot
793
794Not implemented. (S<Mac OS>, Win32, VMS, Plan9)
795
796=item crypt PLAINTEXT,SALT
797
798May not be available if library or source was not provided when building
799perl. (Win32)
800
801=item dbmclose HASH
802
803Not implemented. (VMS, Plan9)
804
805=item dbmopen HASH,DBNAME,MODE
806
807Not implemented. (VMS, Plan9)
808
809=item dump LABEL
810
811Not useful. (S<Mac OS>)
812
813Not implemented. (Win32)
814
815Invokes VMS debugger. (VMS)
816
817=item exec LIST
818
819Not implemented. (S<Mac OS>)
820
821=item fcntl FILEHANDLE,FUNCTION,SCALAR
822
823Not implemented. (Win32, VMS)
824
825=item flock FILEHANDLE,OPERATION
826
827Not implemented (S<Mac OS>, VMS).
828
829Available only on Windows NT (not on Windows 95). (Win32)
830
831=item fork
832
833Not implemented. (S<Mac OS>, Win32, AmigaOS)
834
835=item getlogin
836
837Not implemented. (S<Mac OS>)
838
839=item getpgrp PID
840
841Not implemented. (S<Mac OS>, Win32, VMS)
842
843=item getppid
844
845Not implemented. (S<Mac OS>, Win32, VMS)
846
847=item getpriority WHICH,WHO
848
849Not implemented. (S<Mac OS>, Win32, VMS)
850
851=item getpwnam NAME
852
853Not implemented. (S<Mac OS>, Win32)
854
855=item getgrnam NAME
856
857Not implemented. (S<Mac OS>, Win32, VMS)
858
859=item getnetbyname NAME
860
861Not implemented. (S<Mac OS>, Win32, Plan9)
862
863=item getpwuid UID
864
865Not implemented. (S<Mac OS>, Win32)
866
867=item getgrgid GID
868
869Not implemented. (S<Mac OS>, Win32, VMS)
870
871=item getnetbyaddr ADDR,ADDRTYPE
872
873Not implemented. (S<Mac OS>, Win32, Plan9)
874
875=item getprotobynumber NUMBER
876
877Not implemented. (S<Mac OS>)
878
879=item getservbyport PORT,PROTO
880
881Not implemented. (S<Mac OS>)
882
883=item getpwent
884
885Not implemented. (S<Mac OS>, Win32)
886
887=item getgrent
888
889Not implemented. (S<Mac OS>, Win32, VMS)
890
891=item gethostent
892
893Not implemented. (S<Mac OS>, Win32)
894
895=item getnetent
896
897Not implemented. (S<Mac OS>, Win32, Plan9)
898
899=item getprotoent
900
901Not implemented. (S<Mac OS>, Win32, Plan9)
902
903=item getservent
904
905Not implemented. (Win32, Plan9)
906
907=item setpwent
908
909Not implemented. (S<Mac OS>, Win32)
910
911=item setgrent
912
913Not implemented. (S<Mac OS>, Win32, VMS)
914
915=item sethostent STAYOPEN
916
917Not implemented. (S<Mac OS>, Win32, Plan9)
918
919=item setnetent STAYOPEN
920
921Not implemented. (S<Mac OS>, Win32, Plan9)
922
923=item setprotoent STAYOPEN
924
925Not implemented. (S<Mac OS>, Win32, Plan9)
926
927=item setservent STAYOPEN
928
929Not implemented. (Plan9, Win32)
930
931=item endpwent
932
933Not implemented. (S<Mac OS>, Win32)
934
935=item endgrent
936
937Not implemented. (S<Mac OS>, Win32, VMS)
938
939=item endhostent
940
941Not implemented. (S<Mac OS>, Win32)
942
943=item endnetent
944
945Not implemented. (S<Mac OS>, Win32, Plan9)
946
947=item endprotoent
948
949Not implemented. (S<Mac OS>, Win32, Plan9)
950
951=item endservent
952
953Not implemented. (Plan9, Win32)
954
955=item getsockopt SOCKET,LEVEL,OPTNAME
956
957Not implemented. (S<Mac OS>, Plan9)
958
959=item glob EXPR
960
961=item glob
962
963Globbing built-in, but only C<*> and C<?> metacharacters are supported.
964(S<Mac OS>)
965
966Features depend on external perlglob.exe or perlglob.bat. May be overridden
967with something like File::DosGlob, which is recommended. (Win32)
968
969=item ioctl FILEHANDLE,FUNCTION,SCALAR
970
971Not implemented. (VMS)
972
973Available only for socket handles, and it does what the ioctlsocket() call
974in the Winsock API does. (Win32)
975
976=item kill LIST
977
978Not implemented. (S<Mac OS>)
979
980Available only for process handles returned by the C<system(1, ...)> method of
981spawning a process. (Win32)
982
983=item link OLDFILE,NEWFILE
984
985Not implemented. (S<Mac OS>, Win32, VMS)
986
987=item lstat FILEHANDLE
988
989=item lstat EXPR
990
991=item lstat
992
993Not implemented. (VMS)
994
995Return values may be bogus. (Win32)
996
997=item msgctl ID,CMD,ARG
998
999=item msgget KEY,FLAGS
1000
1001=item msgsnd ID,MSG,FLAGS
1002
1003=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
1004
1005Not implemented. (S<Mac OS>, Win32, VMS, Plan9)
1006
1007=item open FILEHANDLE,EXPR
1008
1009=item open FILEHANDLE
1010
1011The C<|> variants are only supported if ToolServer is installed.
1012(S<Mac OS>)
1013
1014open to C<|-> and C<-|> are unsupported. (S<Mac OS>, Win32)
1015
1016=item pipe READHANDLE,WRITEHANDLE
1017
1018Not implemented. (S<Mac OS>)
1019
1020=item readlink EXPR
1021
1022=item readlink
1023
1024Not implemented. (Win32, VMS)
1025
1026=item select RBITS,WBITS,EBITS,TIMEOUT
1027
1028Only implemented on sockets. (Win32)
1029
1030=item semctl ID,SEMNUM,CMD,ARG
1031
1032=item semget KEY,NSEMS,FLAGS
1033
1034=item semop KEY,OPSTRING
1035
1036Not implemented. (S<Mac OS>, Win32, VMS)
1037
1038=item setpgrp PID,PGRP
1039
1040Not implemented. (S<Mac OS>, Win32, VMS)
1041
1042=item setpriority WHICH,WHO,PRIORITY
1043
1044Not implemented. (S<Mac OS>, Win32, VMS)
1045
1046=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1047
1048Not implemented. (S<Mac OS>, Plan9)
1049
1050=item shmctl ID,CMD,ARG
1051
1052=item shmget KEY,SIZE,FLAGS
1053
1054=item shmread ID,VAR,POS,SIZE
1055
1056=item shmwrite ID,STRING,POS,SIZE
1057
1058Not implemented. (S<Mac OS>, Win32, VMS)
1059
1060=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1061
1062Not implemented. (S<Mac OS>, Win32, VMS)
1063
1064=item stat FILEHANDLE
1065
1066=item stat EXPR
1067
1068=item stat
1069
1070mtime and atime are the same thing, and ctime is creation time instead of
1071inode change time. (S<Mac OS>)
1072
1073device and inode are not meaningful. (Win32)
1074
1075device and inode are not necessarily reliable. (VMS)
1076
1077=item symlink OLDFILE,NEWFILE
1078
1079Not implemented. (Win32, VMS)
1080
1081=item syscall LIST
1082
1083Not implemented. (S<Mac OS>, Win32, VMS)
1084
1085=item system LIST
1086
1087Only implemented if ToolServer is installed. (S<Mac OS>)
1088
1089As an optimization, may not call the command shell specified in
1090C<$ENV{PERL5SHELL}>. C<system(1, @args)> spawns an external
1091process and immediately returns its process designator, without
1092waiting for it to terminate. Return value may be used subsequently
1093in C<wait> or C<waitpid>. (Win32)
1094
1095=item times
1096
1097Only the first entry returned is nonzero. (S<Mac OS>)
1098
1099"cumulative" times will be bogus. On anything other than Windows NT,
1100"system" time will be bogus, and "user" time is actually the time
1101returned by the clock() function in the C runtime library. (Win32)
1102
1103=item truncate FILEHANDLE,LENGTH
1104
1105=item truncate EXPR,LENGTH
1106
1107Not implemented. (VMS)
1108
1109=item umask EXPR
1110
1111=item umask
1112
1113Returns undef where unavailable, as of version 5.005.
1114
1115=item utime LIST
1116
1117Only the modification time is updated. (S<Mac OS>, VMS)
1118
1119May not behave as expected. (Win32)
1120
1121=item wait
1122
1123=item waitpid PID,FLAGS
1124
1125Not implemented. (S<Mac OS>)
1126
1127Can only be applied to process handles returned for processes spawned
1128using C<system(1, ...)>. (Win32)
1129
1130=back
1131
1132
1133=head1 AUTHORS / CONTRIBUTORS
1134
1135Chris Nandor E<lt>pudge@pobox.comE<gt>,
1136Gurusamy Sarathy E<lt>gsar@umich.eduE<gt>,
1137Peter Prymmer E<lt>pvhp@forte.comE<gt>,
1138Tom Christiansen E<lt>tchrist@perl.comE<gt>,
1139Nathan Torkington E<lt>gnat@frii.comE<gt>,
1140Paul Moore E<lt>Paul.Moore@uk.origin-it.comE<gt>,
1141Matthias Neercher E<lt>neeri@iis.ee.ethz.chE<gt>,
1142Charles Bailey E<lt>bailey@genetics.upenn.eduE<gt>,
1143Luther Huffman E<lt>lutherh@stratcom.comE<gt>,
1144Gary Ng E<lt>71564.1743@CompuServe.COME<gt>,
1145Nick Ing-Simmons E<lt>nick@ni-s.u-net.comE<gt>,
1146Paul J. Schinder E<lt>schinder@pobox.comE<gt>,
1147Tom Phoenix E<lt>rootbeer@teleport.comE<gt>,
1148Hugo van der Sanden E<lt>h.sanden@elsevier.nlE<gt>,
1149Dominic Dunlop E<lt>domo@vo.luE<gt>,
1150Dan Sugalski E<lt>sugalskd@ous.eduE<gt>,
1151Andreas J. Koenig E<lt>koenig@kulturbox.deE<gt>,
1152Andrew M. Langmead E<lt>aml@world.std.comE<gt>,
1153Andy Dougherty E<lt>doughera@lafcol.lafayette.eduE<gt>,
1154Abigail E<lt>abigail@fnx.comE<gt>.
1155
1156This document is maintained by Chris Nandor.
1157
1158=head1 VERSION
1159
1160Version 1.23, last modified 10 July 1998.
1161