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