3 perlport - Writing portable Perl
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
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.
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.
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.
31 Be aware of two important points:
35 =item Not all Perl programs have to be portable
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.
42 =item The vast majority of Perl B<is> portable
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.
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.
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
67 This information should not be considered complete; it includes possibly
68 transient information about idiosyncrasies 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>).
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>.
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)
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.
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.
104 print SOCKET "Hi there, client!\r\n"; # WRONG
105 print SOCKET "Hi there, client!\015\012"; # RIGHT
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.]
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.
117 use Socket qw(:DEFAULT :crlf);
118 print SOCKET "Hi there, client!$CRLF" # RIGHT
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>:
130 use Socket qw(:DEFAULT :crlf);
131 local($/) = LF; # not needed if $/ is already \012
134 s/$CR?$LF/\n/; # not sure if socket uses LF or CRLF, OK
135 # s/\015?\012/\n/; # same thing
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).
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.
150 While they are similar, file path specifications differ between Unix,
151 Windows, S<Mac OS>, OS/2, VMS, S<RISC OS> and probably others. Unix,
152 for example, is one of the few OSes that has the idea of a root directory.
153 S<Mac OS> uses C<:> as a path separator instead of C</>. VMS, Windows, and
154 OS/2 can work similarly to Unix with C</> as path separator, or in their own
155 idiosyncratic ways. C<RISC OS> perl can emulate Unix filenames with C</>
156 as path separator, or go native and use C<.> for path separator and C<:>
157 to signal filing systems and disc names.
159 As with the newline problem above, there are modules that can help. The
160 C<File::Spec> modules provide methods to do the Right Thing on whatever
161 platform happens to be running the program.
164 chdir(File::Spec->updir()); # go up one directory
165 $file = File::Spec->catfile(
166 File::Spec->curdir(), 'temp', 'file.txt'
168 # on Unix and Win32, './temp/file.txt'
169 # on Mac OS, ':temp:file.txt'
171 File::Spec is available in the standard distribution, as of version
174 In general, production code should not have file paths hardcoded; making
175 them user supplied or from a configuration file is better, keeping in mind
176 that file path syntax varies on different machines.
178 This is especially noticeable in scripts like Makefiles and test suites,
179 which often assume C</> as a path separator for subdirectories.
181 Also of use is C<File::Basename>, from the standard distribution, which
182 splits a pathname into pieces (base filename, full path to directory,
185 Remember not to count on the existence of system-specific files, like
186 F</etc/resolv.conf>. If code does need to rely on such a file, include a
187 description of the file and its format in the code's documentation, and
188 make it easy for the user to override the default location of the file.
190 Don't assume that a you can open a full pathname for input with
191 C<open (FILE, $name)>, as some platforms can use characters such as C<E<lt>>
192 which will perl C<open> will interpret and eat.
195 =head2 System Interaction
197 Not all platforms provide for the notion of a command line, necessarily.
198 These are usually platforms that rely on a Graphical User Interface (GUI)
199 for user interaction. So a program requiring command lines might not work
200 everywhere. But this is probably for the user of the program to deal
203 Some platforms can't delete or rename files that are being held open by
204 the system. Remember to C<close> files when you are done with them.
205 Don't C<unlink> or C<rename> an open file. Don't C<tie> to or C<open> a
206 file that is already tied to or opened; C<untie> or C<close> first.
208 Don't count on a specific environment variable existing in C<%ENV>.
209 Don't even count on C<%ENV> entries being case-sensitive, or even
212 Don't count on signals in portable programs.
214 Don't count on filename globbing. Use C<opendir>, C<readdir>, and
217 Don't count on per-program environment variables, or per-program current
221 =head2 Interprocess Communication (IPC)
223 In general, don't directly access the system in code that is meant to be
224 portable. That means, no: C<system>, C<exec>, C<fork>, C<pipe>, C<``>,
225 C<qx//>, C<open> with a C<|>, or any of the other things that makes being
226 a Unix perl hacker worth being.
228 Commands that launch external processes are generally supported on
229 most platforms (though many of them do not support any type of forking),
230 but the problem with using them arises from what you invoke with them.
231 External tools are often named differently on different platforms, often
232 not available in the same location, often accept different arguments,
233 often behave differently, and often represent their results in a
234 platform-dependent way. Thus you should seldom depend on them to produce
237 One especially common bit of Perl code is opening a pipe to sendmail:
239 open(MAIL, '|/usr/lib/sendmail -t') or die $!;
241 This is fine for systems programming when sendmail is known to be
242 available. But it is not fine for many non-Unix systems, and even
243 some Unix systems that may not have sendmail installed. If a portable
244 solution is needed, see the C<Mail::Send> and C<Mail::Mailer> modules
245 in the C<MailTools> distribution. C<Mail::Mailer> provides several
246 mailing methods, including mail, sendmail, and direct SMTP
247 (via C<Net::SMTP>) if a mail transfer agent is not available.
249 The rule of thumb for portable code is: Do it all in portable Perl, or
250 use a module that may internally implement it with platform-specific code,
251 but expose a common interface. By portable Perl, we mean code that
252 avoids the constructs described in this document as being non-portable.
255 =head2 External Subroutines (XS)
257 XS code, in general, can be made to work with any platform; but dependent
258 libraries, header files, etc., might not be readily available or
259 portable, or the XS code itself might be platform-specific, just as Perl
260 code might be. If the libraries and headers are portable, then it is
261 normally reasonable to make sure the XS code is portable, too.
263 There is a different kind of portability issue with writing XS
264 code: availability of a C compiler on the end-user's system. C brings with
265 it its own portability issues, and writing XS code will expose you to
266 some of those. Writing purely in perl is a comparatively easier way to
270 =head2 Standard Modules
272 In general, the standard modules work across platforms. Notable
273 exceptions are C<CPAN.pm> (which currently makes connections to external
274 programs that may not be available), platform-specific modules (like
275 C<ExtUtils::MM_VMS>), and DBM modules.
277 There is no one DBM module that is available on all platforms.
278 C<SDBM_File> and the others are generally available on all Unix and DOSish
279 ports, but not in MacPerl, where C<NBDM_File> and C<DB_File> are available.
281 The good news is that at least some DBM module should be available, and
282 C<AnyDBM_File> will use whichever module it can find. Of course, then
283 the code needs to be fairly strict, dropping to the lowest common
284 denominator (e.g., not exceeding 1K for each record).
289 The system's notion of time of day and calendar date is controlled in widely
290 different ways. Don't assume the timezone is stored in C<$ENV{TZ}>, and even
291 if it is, don't assume that you can control the timezone through that
294 Don't assume that the epoch starts at January 1, 1970, because that is
295 OS-specific. Better to store a date in an unambiguous representation.
296 A text representation (like C<1 Jan 1970>) can be easily converted into an
297 OS-specific value using a module like C<Date::Parse>. An array of values,
298 such as those returned by C<localtime>, can be converted to an OS-specific
299 representation using C<Time::Local>.
302 =head2 System Resources
304 If your code is destined for systems with severely constrained (or missing!)
305 virtual memory systems then you want to be especially mindful of avoiding
306 wasteful constructs such as:
308 # NOTE: this is no longer "bad" in perl5.005
309 for (0..10000000) {} # bad
310 for (my $x = 0; $x <= 10000000; ++$x) {} # good
312 @lines = <VERY_LARGE_FILE>; # bad
314 while (<FILE>) {$file .= $_} # sometimes bad
315 $file = join '', <FILE>; # better
317 The last two may appear unintuitive to most people. The first of those
318 two constructs repeatedly grows a string, while the second allocates a
319 large chunk of memory in one go. On some systems, the latter is more
320 efficient that the former.
324 Most Unix platforms provide basic levels of security that is usually felt
325 at the file-system level. Other platforms usually don't (unfortunately).
326 Thus the notion of User-ID, or "home" directory, or even the state of
327 being logged-in may be unrecognizable on may platforms. If you write
328 programs that are security conscious, it is usually best to know what
329 type of system you will be operating under, and write code explicitly
330 for that platform (or class of platforms).
334 For those times when it is necessary to have platform-specific code,
335 consider keeping the platform-specific code in one place, making porting
336 to other platforms easier. Use the C<Config> module and the special
337 variable C<$^O> to differentiate platforms, as described in L<"PLATFORMS">.
342 Module uploaded to CPAN are tested by a variety of volunteers on
343 different platforms. These CPAN testers are notified by e-mail of each
344 new upload, and reply to the list with PASS, FAIL, NA (not applicable to
345 this platform), or ???? (unknown), along with any relevant notations.
347 The purpose of the testing is twofold: one, to help developers fix any
348 problems in their code; two, to provide users with information about
349 whether or not a given module works on a given platform.
353 =item Mailing list: cpan-testers@perl.org
355 =item Testing results: C<http://www.connect.net/gbarr/cpan-test/>
362 As of version 5.002, Perl is built with a C<$^O> variable that
363 indicates the operating system it was built on. This was implemented
364 to help speed up code that would otherwise have to C<use Config;> and
365 use the value of C<$Config{'osname'}>. Of course, to get
366 detailed information about the system, looking into C<%Config> is
367 certainly recommended.
371 Perl works on a bewildering variety of Unix and Unix-like platforms (see
372 e.g. most of the files in the F<hints/> directory in the source code kit).
373 On most of these systems, the value of C<$^O> (hence C<$Config{'osname'}>,
374 too) is determined by lowercasing and stripping punctuation from the first
375 field of the string returned by typing
379 (or a similar command) at the shell prompt. Here, for example, are a few
380 of the more popular Unix flavors:
393 =head2 DOS and Derivatives
395 Perl has long been ported to PC style microcomputers running under
396 systems like PC-DOS, MS-DOS, OS/2, and most Windows platforms you can
397 bring yourself to mention (except for Windows CE, if you count that).
398 Users familiar with I<COMMAND.COM> and/or I<CMD.EXE> style shells should
399 be aware that each of these file specifications may have subtle
402 $filespec0 = "c:/foo/bar/file.txt";
403 $filespec1 = "c:\\foo\\bar\\file.txt";
404 $filespec2 = 'c:\foo\bar\file.txt';
405 $filespec3 = 'c:\\foo\\bar\\file.txt';
407 System calls accept either C</> or C<\> as the path separator. However,
408 many command-line utilities of DOS vintage treat C</> as the option
409 prefix, so they may get confused by filenames containing C</>. Aside
410 from calling any external programs, C</> will work just fine, and
411 probably better, as it is more consistent with popular usage, and avoids
412 the problem of remembering what to backwhack and what not to.
414 The DOS FAT file system can only accommodate "8.3" style filenames. Under
415 the "case insensitive, but case preserving" HPFS (OS/2) and NTFS (NT)
416 file systems you may have to be careful about case returned with functions
417 like C<readdir> or used with functions like C<open> or C<opendir>.
419 DOS also treats several filenames as special, such as AUX, PRN, NUL, CON,
420 COM1, LPT1, LPT2 etc. Unfortunately these filenames won't even work
421 if you include an explicit directory prefix, in some cases. It is best
422 to avoid such filenames, if you want your code to be portable to DOS
425 Users of these operating systems may also wish to make use of
426 scripts such as I<pl2bat.bat> or I<pl2cmd> as appropriate to
427 put wrappers around your scripts.
429 Newline (C<\n>) is translated as C<\015\012> by STDIO when reading from
430 and writing to files. C<binmode(FILEHANDLE)> will keep C<\n> translated
431 as C<\012> for that filehandle. Since it is a noop on other systems,
432 C<binmode> should be used for cross-platform code that deals with binary
435 The C<$^O> variable and the C<$Config{'archname'}> values for various
436 DOSish perls are as follows:
438 OS $^O $Config{'archname'}
439 --------------------------------------------
443 Windows 95 MSWin32 MSWin32-x86
444 Windows NT MSWin32 MSWin32-x86
445 Windows NT MSWin32 MSWin32-alpha
446 Windows NT MSWin32 MSWin32-ppc
452 =item The djgpp environment for DOS, C<http://www.delorie.com/djgpp/>
454 =item The EMX environment for DOS, OS/2, etc. C<emx@iaehv.nl>,
455 C<http://www.juge.com/bbs/Hobb.19.html>
457 =item Build instructions for Win32, L<perlwin32>.
459 =item The ActiveState Pages, C<http://www.activestate.com/>
466 Any module requiring XS compilation is right out for most people, because
467 MacPerl is built using non-free (and non-cheap!) compilers. Some XS
468 modules that can work with MacPerl are built and distributed in binary
469 form on CPAN. See I<MacPerl: Power and Ease> for more details.
471 Directories are specified as:
473 volume:folder:file for absolute pathnames
474 volume:folder: for absolute pathnames
475 :folder:file for relative pathnames
476 :folder: for relative pathnames
477 :file for relative pathnames
478 file for relative pathnames
480 Files in a directory are stored in alphabetical order. Filenames are
481 limited to 31 characters, and may include any character except C<:>,
482 which is reserved as a path separator.
484 Instead of C<flock>, see C<FSpSetFLock> and C<FSpRstFLock> in
487 In the MacPerl application, you can't run a program from the command line;
488 programs that expect C<@ARGV> to be populated can be edited with something
489 like the following, which brings up a dialog box asking for the command
493 @ARGV = split /\s+/, MacPerl::Ask('Arguments?');
496 A MacPerl script saved as a droplet will populate C<@ARGV> with the full
497 pathnames of the files dropped onto the script.
499 Mac users can use programs on a kind of command line under MPW (Macintosh
500 Programmer's Workshop, a free development environment from Apple).
501 MacPerl was first introduced as an MPW tool, and MPW can be used like a
504 perl myscript.plx some arguments
506 ToolServer is another app from Apple that provides access to MPW tools
507 from MPW and the MacPerl app, which allows MacPerl program to use
508 C<system>, backticks, and piped C<open>.
510 "S<Mac OS>" is the proper name for the operating system, but the value
511 in C<$^O> is "MacOS". To determine architecture, version, or whether
512 the application or MPW tool version is running, check:
514 $is_app = $MacPerl::Version =~ /App/;
515 $is_tool = $MacPerl::Version =~ /MPW/;
516 ($version) = $MacPerl::Version =~ /^(\S+)/;
517 $is_ppc = $MacPerl::Architecture eq 'MacPPC';
518 $is_68k = $MacPerl::Architecture eq 'Mac68K';
525 =item The MacPerl Pages, C<http://www.ptf.com/macperl/>.
527 =item The MacPerl mailing list, C<mac-perl-request@iis.ee.ethz.ch>.
534 Perl on VMS is discussed in F<vms/perlvms.pod> in the perl distribution.
535 Note that perl on VMS can accept either VMS or Unix style file
536 specifications as in either of the following:
538 $ perl -ne "print if /perl_setup/i" SYS$LOGIN:LOGIN.COM
539 $ perl -ne "print if /perl_setup/i" /sys$login/login.com
541 but not a mixture of both as in:
543 $ perl -ne "print if /perl_setup/i" sys$login:/login.com
544 Can't open sys$login:/login.com: file specification syntax error
546 Interacting with Perl from the Digital Command Language (DCL) shell
547 often requires a different set of quotation marks than Unix shells do.
550 $ perl -e "print ""Hello, world.\n"""
553 There are a number of ways to wrap your perl scripts in DCL .COM files if
554 you are so inclined. For example:
556 $ write sys$output "Hello from DCL!"
558 $ then perl -x 'f$environment("PROCEDURE")
559 $ else perl -x - 'p1 'p2 'p3 'p4 'p5 'p6 'p7 'p8
560 $ deck/dollars="__END__"
563 print "Hello from Perl!\n";
568 Do take care with C<$ ASSIGN/nolog/user SYS$COMMAND: SYS$INPUT> if your
569 perl-in-DCL script expects to do things like C<$read = E<lt>STDINE<gt>;>.
571 Filenames are in the format "name.extension;version". The maximum
572 length for filenames is 39 characters, and the maximum length for
573 extensions is also 39 characters. Version is a number from 1 to
574 32767. Valid characters are C</[A-Z0-9$_-]/>.
576 VMS' RMS filesystem is case insensitive and does not preserve case.
577 C<readdir> returns lowercased filenames, but specifying a file for
578 opening remains case insensitive. Files without extensions have a
579 trailing period on them, so doing a C<readdir> with a file named F<A.;5>
580 will return F<a.> (though that file could be opened with C<open(FH, 'A')>.
582 RMS has an eight level limit on directory depths from any rooted logical
583 (allowing 16 levels overall). Hence C<PERL_ROOT:[LIB.2.3.4.5.6.7.8]>
584 is a valid directory specification but C<PERL_ROOT:[LIB.2.3.4.5.6.7.8.9]>
585 is not. F<Makefile.PL> authors might have to take this into account, but
586 at least they can refer to the former as C</PERL_ROOT/lib/2/3/4/5/6/7/8/>.
588 The C<VMS::Filespec> module, which gets installed as part
589 of the build process on VMS, is a pure Perl module that can easily be
590 installed on non-VMS platforms and can be helpful for conversions to
591 and from RMS native formats.
593 What C<\n> represents depends on the type of file that is open. It could
594 be C<\015>, C<\012>, C<\015\012>, or nothing. Reading from a file
595 translates newlines to C<\012>, unless C<binmode> was executed on that
596 handle, just like DOSish perls.
598 TCP/IP stacks are optional on VMS, so socket routines might not be
599 implemented. UDP sockets may not be supported.
601 The value of C<$^O> on OpenVMS is "VMS". To determine the architecture
602 that you are running on without resorting to loading all of C<%Config>
603 you can examine the content of the C<@INC> array like so:
605 if (grep(/VMS_AXP/, @INC)) {
606 print "I'm on Alpha!\n";
607 } elsif (grep(/VMS_VAX/, @INC)) {
608 print "I'm on VAX!\n";
610 print "I'm not so sure about where $^O is...\n";
619 =item vmsperl list, C<vmsperl-request@newman.upenn.edu>
621 Put words C<SUBSCRIBE VMSPERL> in message body.
623 =item vmsperl on the web, C<http://www.sidhe.org/vmsperl/index.html>
628 =head2 EBCDIC Platforms
630 Recent versions of Perl have been ported to platforms such as OS/400 on
631 AS/400 minicomputers as well as OS/390 for IBM Mainframes. Such computers
632 use EBCDIC character sets internally (usually Character Code Set ID 00819
633 for OS/400 and IBM-1047 for OS/390). Note that on the mainframe perl
634 currently works under the "Unix system services for OS/390" (formerly
635 known as OpenEdition).
637 As of R2.5 of USS for OS/390 that Unix sub-system did not support the
638 C<#!> shebang trick for script invocation. Hence, on OS/390 perl scripts
639 can executed with a header similar to the following simple script:
642 eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
644 #!/usr/local/bin/perl # just a comment really
646 print "Hello from perl!\n";
648 On these platforms, bear in mind that the EBCDIC character set may have
649 an effect on what happens with perl functions such as C<chr>, C<pack>,
650 C<print>, C<printf>, C<ord>, C<sort>, C<sprintf>, C<unpack>; as well as
651 bit-fiddling with ASCII constants using operators like C<^>, C<&> and
652 C<|>; not to mention dealing with socket interfaces to ASCII computers
655 Fortunately, most web servers for the mainframe will correctly translate
656 the C<\n> in the following statement to its ASCII equivalent (note that
657 C<\r> is the same under both ASCII and EBCDIC):
659 print "Content-type: text/html\r\n\r\n";
661 The value of C<$^O> on OS/390 is "os390".
663 Some simple tricks for determining if you are running on an EBCDIC
664 platform could include any of the following (perhaps all):
666 if ("\t" eq "\05") { print "EBCDIC may be spoken here!\n"; }
668 if (ord('A') == 193) { print "EBCDIC may be spoken here!\n"; }
670 if (chr(169) eq 'z') { print "EBCDIC may be spoken here!\n"; }
672 Note that one thing you may not want to rely on is the EBCDIC encoding
673 of punctuation characters since these may differ from code page to code page
674 (and once your module or script is rumoured to work with EBCDIC, folks will
675 want it to work with all EBCDIC character sets).
683 The perl-mvs@perl.org list is for discussion of porting issues as well as
684 general usage issues for all EBCDIC Perls. Send a message body of
685 "subscribe perl-mvs" to majordomo@perl.org.
687 =item AS/400 Perl information at C<http://as400.rochester.ibm.com>
694 As Acorns use ASCII with newlines (C<\n>) in text files as C<\012> like Unix
695 and Unix filename emulation is turned on by default, it is quite likely that
696 most simple scripts will work "out of the box". The native filing system is
697 modular, and individual filing systems are free to be case sensitive or
698 insensitive, usually case preserving. Some native filing systems have name
699 length limits which file and directory names are silently truncated to fit -
700 scripts should be aware that the standard disc filing system currently has
701 a name length limit of B<10> characters, with up to 77 items in a directory,
702 but other filing systems may not impose such limitations.
704 Native filenames are of the form
706 Filesystem#Special_Field::DiscName.$.Directory.Directory.File
710 Special_Field is not usually present, but may contain . and $ .
711 Filesystem =~ m|[A-Za-z0-9_]|
712 DsicName =~ m|[A-Za-z0-9_/]|
713 $ represents the root directory
714 . is the path separator
715 @ is the current directory (per filesystem but machine global)
716 ^ is the parent directory
717 Directory and File =~ m|[^\0- "\.\$\%\&:\@\\^\|\177]+|
719 The default filename translation is roughly C<tr|/.|./|;>
721 Note that C<"ADFS::HardDisc.$.File" ne 'ADFS::HardDisc.$.File'> and that
722 the second stage of $ interpolation in regular expressions will fall foul
723 of the C<$.> if scripts are not careful.
725 Logical paths specified by system variables containing comma separated
726 search lists are also allowed, hence C<System:Modules> is a valid filename,
727 and the filesystem will prefix C<Modules> with each section of C<System$Path>
728 until a name is made that points to an object on disc. Writing to a new
729 file C<System:Modules> would only be allowed if C<System$Path> contains a
730 single item list. The filesystem will also expand system variables in
731 filenames if enclosed in angle brackets, so C<E<lt>System$DirE<gt>.Modules>
732 would look for the file S<C<$ENV{'System$Dir'} . 'Modules'>>. The obvious
733 implication of this is that B<fully qualified filenames can start with C<E<lt>E<gt>>>
734 and should be protected when C<open> is used for input.
736 Because C<.> was in use as a directory separator and filenames could not
737 be assumed to be unique after 10 characters, Acorn implemented the C
738 compiler to strip the trailing C<.c> C<.h> C<.s> and C<.o> suffix from
739 filenames specified in source code and store the respective files in
740 subdirectories named after the suffix. Hence files are translated:
743 C:foo.h C:h.foo (logical path variable)
744 sys/os.h sys.h.os (C compiler groks Unix-speak)
745 10charname.c c.10charname
746 10charname.o o.10charname
747 11charname_.c c.11charname (assuming filesystem truncates at 10)
749 The Unix emulation library's translation of filenames to native assumes
750 that this sort of translation is required, and allows a user defined list of
751 known suffixes which it will transpose in this fashion. This may appear
752 transparent, but consider that with these rules C<foo/bar/baz.h> and
753 C<foo/bar/h/baz> both map to C<foo.bar.h.baz>, and that C<readdir> and
754 C<glob> cannot and do not attempt to emulate the reverse mapping. Other '.'s
755 in filenames are translated to '/'.
757 S<RISC OS> has "image files", files that behave as directories. For
758 example with suitable software this allows the contents of a zip file to
759 be treated as a directory at command line (and therefore script) level,
760 with full read-write random access. At present the perl port treats images
761 as directories: C<-d> returns true, C<-f> false, and C<unlink> checks to
762 ensure that recognised images are empty before deleting them. In theory
763 images should never trouble a script, but in practice they may do so if
764 the software to deal with an image file is loaded and registered while the
765 script is running, as suddenly "files" that it had cached information on
766 metamorphose into directories.
768 As implied above the environment accessed through C<%ENV> is global, and the
769 convention is that program specific environment variables are of the form
770 C<Program$Name>. Each filing system maintains a current directory, and
771 the current filing system's current directory is the B<global> current
772 directory. Consequently sociable scripts don't change the current directory
773 but rely on full pathnames, and scripts (and Makefiles) cannot assume that
774 they can spawn a child process which can change the current directory
775 without affecting its parent (and everyone else for that matter).
777 As native operating system filehandles are global and currently are allocated
778 down from 255, with 0 being a reserved value the Unix emulation library
779 emulates Unix filehandles. Consequently you can't rely on passing C<STDIN>
780 C<STDOUT> or C<STDERR> to your children. Run time libraries perform
781 command line processing to emulate Unix shell style C<>> redirection, but
782 the core operating system is written in assembler and has its own private,
783 obscure and somewhat broken convention. All this is further complicated by
784 the desire of users to express filenames of the form C<E<lt>Foo$DirE<gt>.Bar> on
785 the command line unquoted. (Oh yes, it's run time libraries interpreting the
786 quoting convention.) Hence C<``> command output capture has to perform
787 a guessing game as to how the command is going to interpret the command line
788 so that it can bodge it correctly to capture output. It assumes that a
789 string C<E<lt>[^E<lt>E<gt>]+\$[^E<lt>E<gt>]E<gt>> is a reference to an environment
790 variable, whereas anything else involving C<E<lt>> or C<E<gt>> is redirection,
791 and generally manages to be 99% right. Despite all this the problem remains
792 that scripts cannot rely on any Unix tools being available, or that any tools
793 found have Unix-like command line arguments.
795 Extensions and XS are in theory buildable by anyone using free tools. In
796 practice many don't as the Acorn platform is used to binary distribution.
797 MakeMaker does itself run, but no make currently copes with MakeMaker's
798 makefiles! Even if (when) this is fixed os that the lack of a Unix-like
799 shell can cause problems with makefile rules, especially lines of the form
800 C<cd sdbm && make all> and anything using quoting.
802 "S<RISC OS>" is the proper name for the operating system, but the value
803 in C<$^O> is "riscos" (because we don't like shouting).
816 Perl has been ported to a variety of platforms that do not fit into any of
817 the above categories. Some, such as AmigaOS, BeOS, QNX, and Plan 9, have
818 been well integrated into the standard Perl source code kit. You may need
819 to see the F<ports/> directory on CPAN for information, and possibly
820 binaries, for the likes of: aos, atari, lynxos, HP-MPE/iX, riscos,
821 Tandem Guardian, vos, I<etc.> (yes we know that some of these OSes may fall
822 under the Unix category but we are not a standards body.)
828 =item Atari, Guido Flohr's page C<http://stud.uni-sb.de/~gufl0000/>
830 =item HP 300 MPE/iX C<http://www.cccd.edu/~markb/perlix.html>
834 A free Perl 5 based PERL.NLM for Novell Netware is available from
835 C<http://www.novell.com/>
840 =head1 FUNCTION IMPLEMENTATIONS
842 Listed below are functions unimplemented or implemented differently on
843 various platforms. Following each description will be, in parentheses, a
844 list of platforms that the description applies to.
846 The list may very well be incomplete, or wrong in some places. When in
847 doubt, consult the platform-specific README files in the Perl source
848 distribution, and other documentation resources for a given port.
850 Be aware, moreover, that even among Unix-ish systems there are variations,
851 and not all functions listed here are necessarily available, though
854 For many functions, you can also query C<%Config>, exported by default
855 from C<Config.pm>. For example, to check if the platform has the C<lstat>
856 call, check C<$Config{'d_lstat'}>. See L<Config> for a full description
857 of available variables.
860 =head2 Alphabetical Listing of Perl Functions
870 C<-r>, C<-w>, and C<-x> have only a very limited meaning; directories
871 and applications are executable, and there are no uid/gid
872 considerations. C<-o> is not supported. (S<Mac OS>)
874 C<-r>, C<-w>, C<-x>, and C<-o> tell whether or not file is accessible,
875 which may not reflect UIC-based file protections. (VMS)
877 C<-s> returns the size of the data fork, not the total size of data fork
878 plus resource fork. (S<Mac OS>).
880 C<-s> by name on an open file will return the space reserved on disk,
881 rather than the current extent. C<-s> on an open filehandle returns the
882 current size. (S<RISC OS>)
884 C<-R>, C<-W>, C<-X>, C<-O> are indistinguishable from C<-r>, C<-w>,
885 C<-x>, C<-o>. (S<Mac OS>, Win32, VMS, S<RISC OS>)
887 C<-b>, C<-c>, C<-k>, C<-g>, C<-p>, C<-u>, C<-A> are not implemented.
890 C<-g>, C<-k>, C<-l>, C<-p>, C<-u>, C<-A> are not particularly meaningful.
891 (Win32, VMS, S<RISC OS>)
893 C<-d> is true if passed a device spec without an explicit directory.
896 C<-T> and C<-B> are implemented, but might misclassify Mac text files
897 with foreign characters; this is the case will all platforms, but
898 affects S<Mac OS> a lot. (S<Mac OS>)
900 C<-x> (or C<-X>) determine if a file ends in one of the executable
901 suffixes. C<-S> is meaningless. (Win32)
903 C<-x> (or C<-X>) determine if a file has an executable file type.
906 =item binmode FILEHANDLE
908 Meaningless. (S<Mac OS>, S<RISC OS>)
910 Reopens file and restores pointer; if function fails, underlying
911 filehandle may be closed, or pointer may be in a different position.
914 The value returned by C<tell> may be affected after the call, and
915 the filehandle may be flushed. (Win32)
919 Only limited meaning. Disabling/enabling write permission is mapped to
920 locking/unlocking the file. (S<Mac OS>)
922 Only good for changing "owner" read-write access, "group", and "other"
923 bits are meaningless. (Win32)
925 Only good for changing "owner" and "other" read-write access. (S<RISC OS>)
929 Not implemented. (S<Mac OS>, Win32, Plan9, S<RISC OS>)
931 Does nothing, but won't fail. (Win32)
933 =item chroot FILENAME
937 Not implemented. (S<Mac OS>, Win32, VMS, Plan9, S<RISC OS>)
939 =item crypt PLAINTEXT,SALT
941 May not be available if library or source was not provided when building
946 Not implemented. (VMS, Plan9)
948 =item dbmopen HASH,DBNAME,MODE
950 Not implemented. (VMS, Plan9)
954 Not useful. (S<Mac OS>, S<RISC OS>)
956 Not implemented. (Win32)
958 Invokes VMS debugger. (VMS)
962 Not implemented. (S<Mac OS>)
964 =item fcntl FILEHANDLE,FUNCTION,SCALAR
966 Not implemented. (Win32, VMS)
968 =item flock FILEHANDLE,OPERATION
970 Not implemented (S<Mac OS>, VMS, S<RISC OS>).
972 Available only on Windows NT (not on Windows 95). (Win32)
976 Not implemented. (S<Mac OS>, Win32, AmigaOS, S<RISC OS>)
980 Not implemented. (S<Mac OS>, S<RISC OS>)
984 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
988 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
990 =item getpriority WHICH,WHO
992 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
996 Not implemented. (S<Mac OS>, Win32)
998 Not useful. (S<RISC OS>)
1002 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1004 =item getnetbyname NAME
1006 Not implemented. (S<Mac OS>, Win32, Plan9)
1010 Not implemented. (S<Mac OS>, Win32)
1012 Not useful. (S<RISC OS>)
1016 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1018 =item getnetbyaddr ADDR,ADDRTYPE
1020 Not implemented. (S<Mac OS>, Win32, Plan9)
1022 =item getprotobynumber NUMBER
1024 Not implemented. (S<Mac OS>)
1026 =item getservbyport PORT,PROTO
1028 Not implemented. (S<Mac OS>)
1032 Not implemented. (S<Mac OS>, Win32)
1036 Not implemented. (S<Mac OS>, Win32, VMS)
1040 Not implemented. (S<Mac OS>, Win32)
1044 Not implemented. (S<Mac OS>, Win32, Plan9)
1048 Not implemented. (S<Mac OS>, Win32, Plan9)
1052 Not implemented. (Win32, Plan9)
1056 Not implemented. (S<Mac OS>, Win32, S<RISC OS>)
1060 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1062 =item sethostent STAYOPEN
1064 Not implemented. (S<Mac OS>, Win32, Plan9, S<RISC OS>)
1066 =item setnetent STAYOPEN
1068 Not implemented. (S<Mac OS>, Win32, Plan9, S<RISC OS>)
1070 =item setprotoent STAYOPEN
1072 Not implemented. (S<Mac OS>, Win32, Plan9, S<RISC OS>)
1074 =item setservent STAYOPEN
1076 Not implemented. (Plan9, Win32, S<RISC OS>)
1080 Not implemented. (S<Mac OS>, Win32)
1084 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1088 Not implemented. (S<Mac OS>, Win32)
1092 Not implemented. (S<Mac OS>, Win32, Plan9)
1096 Not implemented. (S<Mac OS>, Win32, Plan9)
1100 Not implemented. (Plan9, Win32)
1102 =item getsockopt SOCKET,LEVEL,OPTNAME
1104 Not implemented. (S<Mac OS>, Plan9)
1110 Globbing built-in, but only C<*> and C<?> metacharacters are supported.
1113 Features depend on external perlglob.exe or perlglob.bat. May be overridden
1114 with something like File::DosGlob, which is recommended. (Win32)
1116 Globbing built-in, but only C<*> and C<?> metacharacters are supported.
1117 Globbing relies on operating system calls, which may return filenames in
1118 any order. As most filesystems are case insensitive even "sorted"
1119 filenames will not be in case sensitive order. (S<RISC OS>)
1121 =item ioctl FILEHANDLE,FUNCTION,SCALAR
1123 Not implemented. (VMS)
1125 Available only for socket handles, and it does what the ioctlsocket() call
1126 in the Winsock API does. (Win32)
1128 Available only for socket handles. (S<RISC OS>)
1132 Not implemented, hence not useful for taint checking. (S<Mac OS>, S<RISC OS>)
1134 Available only for process handles returned by the C<system(1, ...)> method of
1135 spawning a process. (Win32)
1137 =item link OLDFILE,NEWFILE
1139 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1141 =item lstat FILEHANDLE
1147 Not implemented. (VMS, S<RISC OS>)
1149 Return values may be bogus. (Win32)
1151 =item msgctl ID,CMD,ARG
1153 =item msgget KEY,FLAGS
1155 =item msgsnd ID,MSG,FLAGS
1157 =item msgrcv ID,VAR,SIZE,TYPE,FLAGS
1159 Not implemented. (S<Mac OS>, Win32, VMS, Plan9, S<RISC OS>)
1161 =item open FILEHANDLE,EXPR
1163 =item open FILEHANDLE
1165 The C<|> variants are only supported if ToolServer is installed.
1168 open to C<|-> and C<-|> are unsupported. (S<Mac OS>, Win32, S<RISC OS>)
1170 =item pipe READHANDLE,WRITEHANDLE
1172 Not implemented. (S<Mac OS>)
1178 Not implemented. (Win32, VMS, S<RISC OS>)
1180 =item select RBITS,WBITS,EBITS,TIMEOUT
1182 Only implemented on sockets. (Win32)
1184 Only reliable on sockets. (S<RISC OS>)
1186 =item semctl ID,SEMNUM,CMD,ARG
1188 =item semget KEY,NSEMS,FLAGS
1190 =item semop KEY,OPSTRING
1192 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1194 =item setpgrp PID,PGRP
1196 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1198 =item setpriority WHICH,WHO,PRIORITY
1200 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1202 =item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1204 Not implemented. (S<Mac OS>, Plan9)
1206 =item shmctl ID,CMD,ARG
1208 =item shmget KEY,SIZE,FLAGS
1210 =item shmread ID,VAR,POS,SIZE
1212 =item shmwrite ID,STRING,POS,SIZE
1214 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1216 =item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1218 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1220 =item stat FILEHANDLE
1226 mtime and atime are the same thing, and ctime is creation time instead of
1227 inode change time. (S<Mac OS>)
1229 device and inode are not meaningful. (Win32)
1231 device and inode are not necessarily reliable. (VMS)
1233 mtime, atime and ctime all return the last modification time. Device and
1234 inode are not necessarily reliable. (S<RISC OS>)
1236 =item symlink OLDFILE,NEWFILE
1238 Not implemented. (Win32, VMS, S<RISC OS>)
1242 Not implemented. (S<Mac OS>, Win32, VMS, S<RISC OS>)
1246 Only implemented if ToolServer is installed. (S<Mac OS>)
1248 As an optimization, may not call the command shell specified in
1249 C<$ENV{PERL5SHELL}>. C<system(1, @args)> spawns an external
1250 process and immediately returns its process designator, without
1251 waiting for it to terminate. Return value may be used subsequently
1252 in C<wait> or C<waitpid>. (Win32)
1254 There is no shell to process metacharacters, and the native standard is
1255 to pass a command line terminated by "\n" "\r" or "\0" to the spawned
1256 program. Redirection such as C<E<gt> foo> is performed (if at all) by
1257 the run time library of the spawned program. C<system> I<list> will call
1258 the Unix emulation library's C<exec> emulation, which attempts to provide
1259 emulation of the stdin, stdout, stderr in force in the parent, providing
1260 the child program uses a compatible version of the emulation library.
1261 I<scalar> will call the native command line direct and no such emulation
1262 of a child Unix program will exists. Mileage B<will> vary. (S<RISC OS>)
1266 Only the first entry returned is nonzero. (S<Mac OS>)
1268 "cumulative" times will be bogus. On anything other than Windows NT,
1269 "system" time will be bogus, and "user" time is actually the time
1270 returned by the clock() function in the C runtime library. (Win32)
1272 Not useful. (S<RISC OS>)
1274 =item truncate FILEHANDLE,LENGTH
1276 =item truncate EXPR,LENGTH
1278 Not implemented. (VMS)
1284 Returns undef where unavailable, as of version 5.005.
1288 Only the modification time is updated. (S<Mac OS>, VMS, S<RISC OS>)
1290 May not behave as expected. (Win32)
1294 =item waitpid PID,FLAGS
1296 Not implemented. (S<Mac OS>)
1298 Can only be applied to process handles returned for processes spawned
1299 using C<system(1, ...)>. (Win32)
1301 Not useful. (S<RISC OS>)
1309 =item 1.30, 03 August 1998
1311 Major update for RISC OS, other minor changes.
1313 =item 1.23, 10 July 1998
1315 First public release with perl5.005.
1319 =head1 AUTHORS / CONTRIBUTORS
1321 Chris Nandor E<lt>pudge@pobox.comE<gt>,
1322 Gurusamy Sarathy E<lt>gsar@umich.eduE<gt>,
1323 Peter Prymmer E<lt>pvhp@forte.comE<gt>,
1324 Tom Christiansen E<lt>tchrist@perl.comE<gt>,
1325 Nathan Torkington E<lt>gnat@frii.comE<gt>,
1326 Paul Moore E<lt>Paul.Moore@uk.origin-it.comE<gt>,
1327 Matthias Neercher E<lt>neeri@iis.ee.ethz.chE<gt>,
1328 Charles Bailey E<lt>bailey@genetics.upenn.eduE<gt>,
1329 Luther Huffman E<lt>lutherh@stratcom.comE<gt>,
1330 Gary Ng E<lt>71564.1743@CompuServe.COME<gt>,
1331 Nick Ing-Simmons E<lt>nick@ni-s.u-net.comE<gt>,
1332 Paul J. Schinder E<lt>schinder@pobox.comE<gt>,
1333 Tom Phoenix E<lt>rootbeer@teleport.comE<gt>,
1334 Hugo van der Sanden E<lt>h.sanden@elsevier.nlE<gt>,
1335 Dominic Dunlop E<lt>domo@vo.luE<gt>,
1336 Dan Sugalski E<lt>sugalskd@ous.eduE<gt>,
1337 Andreas J. Koenig E<lt>koenig@kulturbox.deE<gt>,
1338 Andrew M. Langmead E<lt>aml@world.std.comE<gt>,
1339 Andy Dougherty E<lt>doughera@lafcol.lafayette.eduE<gt>,
1340 Abigail E<lt>abigail@fnx.comE<gt>,
1341 Nicholas Clark E<lt>Nicholas.Clark@liverpool.ac.ukE<gt>.
1343 This document is maintained by Chris Nandor.
1347 Version 1.30, last modified 03 August 1998.