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