PLATFORMS
As of version 5.002, Perl is built with a $^O variable that indicates the
operating system it was built on. This was implemented to help speed up code that would
otherwise have to use Config and use the value of $Config{osname}.
Of course, to get more detailed information about the system, looking into %Config
is certainly recommended.
%Config cannot always be trusted, however, because it was built at compile
time. If perl was built in one place, then transferred elsewhere, some values may be wrong.
The values may even have been edited after the fact.
Perl works on a bewildering variety of Unix and Unix-like platforms (see e.g. most of the
files in the hints/ directory in the source code kit). On most of these systems, the
value of $^O (hence $Config{'osname'}, too) is determined either by
lowercasing and stripping punctuation from the first field of the string returned by typing uname
-a (or a similar command) at the shell prompt or by testing the file system for the
presence of uniquely named files such as a kernel or header file. Here, for example, are a few
of the more popular Unix flavors:
uname $^O $Config{'archname'}
--------------------------------------------
AIX aix aix
BSD/OS bsdos i386-bsdos
Darwin darwin darwin
dgux dgux AViiON-dgux
DYNIX/ptx dynixptx i386-dynixptx
FreeBSD freebsd freebsd-i386
Linux linux arm-linux
Linux linux i386-linux
Linux linux i586-linux
Linux linux ppc-linux
HP-UX hpux PA-RISC1.1
IRIX irix irix
Mac OS X darwin darwin
MachTen PPC machten powerpc-machten
NeXT 3 next next-fat
NeXT 4 next OPENSTEP-Mach
openbsd openbsd i386-openbsd
OSF1 dec_osf alpha-dec_osf
reliantunix-n svr4 RM400-svr4
SCO_SV sco_sv i386-sco_sv
SINIX-N svr4 RM400-svr4
sn4609 unicos CRAY_C90-unicos
sn6521 unicosmk t3e-unicosmk
sn9617 unicos CRAY_J90-unicos
SunOS solaris sun4-solaris
SunOS solaris i86pc-solaris
SunOS4 sunos sun4-sunos
|
|
Because the value of $Config{archname} may depend on the hardware
architecture, it can vary more than the value of $^O.
Perl has long been ported to Intel-style microcomputers running under systems like PC-DOS,
MS-DOS, OS/2, and most Windows platforms you can bring yourself to mention (except for Windows
CE, if you count that). Users familiar with COMMAND.COM or CMD.EXE style shells
should be aware that each of these file specifications may have subtle differences:
$filespec0 = "c:/foo/bar/file.txt";
$filespec1 = "c:\\foo\\bar\\file.txt";
$filespec2 = 'c:\foo\bar\file.txt';
$filespec3 = 'c:\\foo\\bar\\file.txt';
|
|
System calls accept either / or \ as the path separator. However,
many command-line utilities of DOS vintage treat / as the option prefix, so may
get confused by filenames containing /. Aside from calling any external programs,
/ will work just fine, and probably better, as it is more consistent with popular
usage, and avoids the problem of remembering what to backwhack and what not to.
The DOS FAT filesystem can accommodate only "8.3" style filenames. Under the
"case-insensitive, but case-preserving" HPFS (OS/2) and NTFS (NT) filesystems you
may have to be careful about case returned with functions like readdir or used
with functions like open or opendir.
DOS also treats several filenames as special, such as AUX, PRN, NUL, CON, COM1, LPT1, LPT2,
etc. Unfortunately, sometimes these filenames won't even work if you include an explicit
directory prefix. It is best to avoid such filenames, if you want your code to be portable to
DOS and its derivatives. It's hard to know what these all are, unfortunately.
Users of these operating systems may also wish to make use of scripts such as pl2bat.bat
or pl2cmd to put wrappers around your scripts.
Newline (\n) is translated as \015\012 by STDIO when reading from
and writing to files (see "Newlines"). binmode(FILEHANDLE)
will keep \n translated as \012 for that filehandle. Since it is a
no-op on other systems, binmode should be used for cross-platform code that deals
with binary data. That's assuming you realize in advance that your data is in binary.
General-purpose programs should often assume nothing about their data.
The $^O variable and the $Config{archname} values for various
DOSish perls are as follows:
OS $^O $Config{archname} ID Version
--------------------------------------------------------
MS-DOS dos ?
PC-DOS dos ?
OS/2 os2 ?
Windows 3.1 ? ? 0 3 01
Windows 95 MSWin32 MSWin32-x86 1 4 00
Windows 98 MSWin32 MSWin32-x86 1 4 10
Windows ME MSWin32 MSWin32-x86 1 ?
Windows NT MSWin32 MSWin32-x86 2 4 xx
Windows NT MSWin32 MSWin32-ALPHA 2 4 xx
Windows NT MSWin32 MSWin32-ppc 2 4 xx
Windows 2000 MSWin32 MSWin32-x86 2 5 xx
Windows XP MSWin32 MSWin32-x86 2 ?
Windows CE MSWin32 ? 3
Cygwin cygwin ?
|
|
The various MSWin32 Perl's can distinguish the OS they are running on via the value of the
fifth element of the list returned from Win32::GetOSVersion(). For example:
if ($^O eq 'MSWin32') {
my @os_version_info = Win32::GetOSVersion();
print +('3.1','95','NT')[$os_version_info[4]],"\n";
}
|
|
There are also Win32::IsWinNT() and Win32::IsWin95(), try perldoc Win32, and
as of libwin32 0.19 (not part of the core Perl distribution) Win32::GetOSName(). The very
portable POSIX::uname() will work too:
c:\> perl -MPOSIX -we "print join '|', uname"
Windows NT|moonru|5.0|Build 2195 (Service Pack 2)|x86
|
|
Also see:
- The djgpp environment for DOS, http://www.delorie.com/djgpp/ and perldos.
- The EMX environment for DOS, OS/2, etc. emx@iaehv.nl, http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/index.html
or ftp://hobbes.nmsu.edu/pub/os2/dev/emx/ Also perlos2.
- Build instructions for Win32 in perlwin32, or under the
Cygnus environment in perlcygwin.
- The
Win32::* modules in Win32.
- The ActiveState Pages, http://www.activestate.com/
- The Cygwin environment for Win32; README.cygwin (installed as perlcygwin), http://www.cygwin.com/
- The U/WIN environment for Win32, http://www.research.att.com/sw/tools/uwin/
- Build instructions for OS/2, perlos2
Any module requiring XS compilation is right out for most people, because MacPerl is built
using non-free (and non-cheap!) compilers. Some XS modules that can work with MacPerl are
built and distributed in binary form on CPAN.
Directories are specified as:
volume:folder:file for absolute pathnames
volume:folder: for absolute pathnames
:folder:file for relative pathnames
:folder: for relative pathnames
:file for relative pathnames
file for relative pathnames
|
|
Files are stored in the directory in alphabetical order. Filenames are limited to 31
characters, and may include any character except for null and :, which is
reserved as the path separator.
Instead of flock, see FSpSetFLock and FSpRstFLock in
the Mac::Files module, or chmod(0444, ...) and chmod(0666, ...).
In the MacPerl application, you can't run a program from the command line; programs that
expect @ARGV to be populated can be edited with something like the following,
which brings up a dialog box asking for the command line arguments.
if (!@ARGV) {
@ARGV = split /\s+/, MacPerl::Ask('Arguments?');
}
|
|
A MacPerl script saved as a "droplet" will populate @ARGV with the
full pathnames of the files dropped onto the script.
Mac users can run programs under a type of command line interface under MPW (Macintosh
Programmer's Workshop, a free development environment from Apple). MacPerl was first
introduced as an MPW tool, and MPW can be used like a shell:
perl myscript.plx some arguments
|
|
ToolServer is another app from Apple that provides access to MPW tools from MPW and the
MacPerl app, which allows MacPerl programs to use system, backticks, and piped open.
"Mac OS" is the proper name for the operating system, but the value in $^O
is "MacOS". To determine architecture, version, or whether the application or MPW
tool version is running, check:
$is_app = $MacPerl::Version =~ /App/;
$is_tool = $MacPerl::Version =~ /MPW/;
($version) = $MacPerl::Version =~ /^(\S+)/;
$is_ppc = $MacPerl::Architecture eq 'MacPPC';
$is_68k = $MacPerl::Architecture eq 'Mac68K';
|
|
Mac OS X, based on NeXT's OpenStep OS, runs MacPerl natively, under the
"Classic" environment. There is no "Carbon" version of MacPerl to run
under the primary Mac OS X environment. Mac OS X and its Open Source version,
Darwin, both run Unix perl natively.
Also see:
- MacPerl Development, http://dev.macperl.org/ .
- The MacPerl Pages, http://www.macperl.com/ .
- The MacPerl mailing lists, http://lists.perl.org/ .
Perl on VMS is discussed in perlvms
in the perl distribution. Perl on VMS can accept either VMS- or Unix-style file specifications
as in either of the following:
$ perl -ne "print if /perl_setup/i" SYS$LOGIN:LOGIN.COM
$ perl -ne "print if /perl_setup/i" /sys$login/login.com
|
|
but not a mixture of both as in:
$ perl -ne "print if /perl_setup/i" sys$login:/login.com
Can't open sys$login:/login.com: file specification syntax error
|
|
Interacting with Perl from the Digital Command Language (DCL) shell often requires a
different set of quotation marks than Unix shells do. For example:
$ perl -e "print ""Hello, world.\n"""
Hello, world.
|
|
There are several ways to wrap your perl scripts in DCL .COM files, if you are so
inclined. For example:
$ write sys$output "Hello from DCL!"
$ if p1 .eqs. ""
$ then perl -x 'f$environment("PROCEDURE")
$ else perl -x - 'p1 'p2 'p3 'p4 'p5 'p6 'p7 'p8
$ deck/dollars="__END__"
#!/usr/bin/perl
print "Hello from Perl!\n";
__END__
$ endif
|
|
Do take care with $ ASSIGN/nolog/user SYS$COMMAND: SYS$INPUT if your
perl-in-DCL script expects to do things like $read = <STDIN>;.
Filenames are in the format "name.extension;version". The maximum length for
filenames is 39 characters, and the maximum length for extensions is also 39 characters.
Version is a number from 1 to 32767. Valid characters are /[A-Z0-9$_-]/.
VMS's RMS filesystem is case-insensitive and does not preserve case. readdir
returns lowercased filenames, but specifying a file for opening remains case-insensitive.
Files without extensions have a trailing period on them, so doing a readdir with
a file named A.;5 will return a. (though that file could be opened with open(FH,
'A')).
RMS had an eight level limit on directory depths from any rooted logical (allowing 16
levels overall) prior to VMS 7.2. Hence PERL_ROOT:[LIB.2.3.4.5.6.7.8] is a valid
directory specification but PERL_ROOT:[LIB.2.3.4.5.6.7.8.9] is not. Makefile.PL
authors might have to take this into account, but at least they can refer to the former as /PERL_ROOT/lib/2/3/4/5/6/7/8/.
The VMS::Filespec module, which gets installed as part of the build process on VMS, is a
pure Perl module that can easily be installed on non-VMS platforms and can be helpful for
conversions to and from RMS native formats.
What \n represents depends on the type of file opened. It usually represents \012
but it could also be \015, \012, \015\012, \000,
\040, or nothing depending on the file organiztion and record format. The
VMS::Stdio module provides access to the special fopen() requirements of files with unusual
attributes on VMS.
TCP/IP stacks are optional on VMS, so socket routines might not be implemented. UDP sockets
may not be supported.
The value of $^O on OpenVMS is "VMS". To determine the architecture
that you are running on without resorting to loading all of %Config you can
examine the content of the @INC array like so:
if (grep(/VMS_AXP/, @INC)) {
print "I'm on Alpha!\n";
} elsif (grep(/VMS_VAX/, @INC)) {
print "I'm on VAX!\n";
} else {
print "I'm not so sure about where $^O is...\n";
}
|
|
On VMS, perl determines the UTC offset from the SYS$TIMEZONE_DIFFERENTIAL
logical name. Although the VMS epoch began at 17-NOV-1858 00:00:00.00, calls to localtime
are adjusted to count offsets from 01-JAN-1970 00:00:00.00, just like Unix.
Also see:
Perl on VOS is discussed in README.vos in the perl distribution (installed as perlvos). Perl on VOS can accept
either VOS- or Unix-style file specifications as in either of the following:
C<< $ perl -ne "print if /perl_setup/i" >system>notices >>
C<< $ perl -ne "print if /perl_setup/i" /system/notices >>
|
|
or even a mixture of both as in:
C<< $ perl -ne "print if /perl_setup/i" >system/notices >>
|
|
Even though VOS allows the slash character to appear in object names, because the VOS port
of Perl interprets it as a pathname delimiting character, VOS files, directories, or links
whose names contain a slash character cannot be processed. Such files must be renamed before
they can be processed by Perl. Note that VOS limits file names to 32 or fewer characters.
Perl on VOS can be built using two different compilers and two different versions of the
POSIX runtime. The recommended method for building full Perl is with the GNU C compiler and
the generally-available version of VOS POSIX support. See README.vos (installed as perlvos) for restrictions that
apply when Perl is built using the VOS Standard C compiler or the alpha version of VOS POSIX
support.
The value of $^O on VOS is "VOS". To determine the architecture that
you are running on without resorting to loading all of %Config you can examine
the content of the @INC array like so:
if ($^O =~ /VOS/) {
print "I'm on a Stratus box!\n";
} else {
print "I'm not on a Stratus box!\n";
die;
}
if (grep(/860/, @INC)) {
print "This box is a Stratus XA/R!\n";
} elsif (grep(/7100/, @INC)) {
print "This box is a Stratus HP 7100 or 8xxx!\n";
} elsif (grep(/8000/, @INC)) {
print "This box is a Stratus HP 8xxx!\n";
} else {
print "This box is a Stratus 68K!\n";
}
|
|
Also see:
Recent versions of Perl have been ported to platforms such as OS/400 on AS/400
minicomputers as well as OS/390, VM/ESA, and BS2000 for S/390 Mainframes. Such computers use
EBCDIC character sets internally (usually Character Code Set ID 0037 for OS/400 and either
1047 or POSIX-BC for S/390 systems). On the mainframe perl currently works under the
"Unix system services for OS/390" (formerly known as OpenEdition), VM/ESA
OpenEdition, or the BS200 POSIX-BC system (BS2000 is supported in perl 5.6 and greater). See perlos390 for details.
As of R2.5 of USS for OS/390 and Version 2.3 of VM/ESA these Unix sub-systems do not
support the #! shebang trick for script invocation. Hence, on OS/390 and VM/ESA
perl scripts can be executed with a header similar to the following simple script:
: # use perl
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
if 0;
#!/usr/local/bin/perl # just a comment really
print "Hello from perl!\n";
|
|
OS/390 will support the #! shebang trick in release 2.8 and beyond. Calls to system
and backticks can use POSIX shell syntax on all S/390 systems.
On the AS/400, if PERL5 is in your library list, you may need to wrap your perl scripts in
a CL procedure to invoke them like so:
BEGIN
CALL PGM(PERL5/PERL) PARM('/QOpenSys/hello.pl')
ENDPGM
|
|
This will invoke the perl script hello.pl in the root of the QOpenSys file system.
On the AS/400 calls to system or backticks must use CL syntax.
On these platforms, bear in mind that the EBCDIC character set may have an effect on what
happens with some perl functions (such as chr, pack, print,
printf, ord, sort, sprintf, unpack),
as well as bit-fiddling with ASCII constants using operators like ^, &
and |, not to mention dealing with socket interfaces to ASCII computers (see "Newlines").
Fortunately, most web servers for the mainframe will correctly translate the \n
in the following statement to its ASCII equivalent (\r is the same under both
Unix and OS/390 & VM/ESA):
print "Content-type: text/html\r\n\r\n";
|
|
The values of $^O on some of these platforms includes:
uname $^O $Config{'archname'}
--------------------------------------------
OS/390 os390 os390
OS400 os400 os400
POSIX-BC posix-bc BS2000-posix-bc
VM/ESA vmesa vmesa
|
|
Some simple tricks for determining if you are running on an EBCDIC platform could include
any of the following (perhaps all):
if ("\t" eq "\05") { print "EBCDIC may be spoken here!\n"; }
if (ord('A') == 193) { print "EBCDIC may be spoken here!\n"; }
if (chr(169) eq 'z') { print "EBCDIC may be spoken here!\n"; }
|
|
One thing you may not want to rely on is the EBCDIC encoding of punctuation characters
since these may differ from code page to code page (and once your module or script is rumoured
to work with EBCDIC, folks will want it to work with all EBCDIC character sets).
Also see:
-
*
perlos390, README.os390,
perlbs2000, README.vmesa, perlebcdic.
- The perl-mvs@perl.org list is for discussion of porting issues as well as general usage
issues for all EBCDIC Perls. Send a message body of "subscribe perl-mvs" to
majordomo@perl.org.
- AS/400 Perl information at http://as400.rochester.ibm.com/ as well as on CPAN in the ports/
directory.
Because Acorns use ASCII with newlines (\n) in text files as \012
like Unix, and because Unix filename emulation is turned on by default, most simple scripts
will probably work "out of the box". The native filesystem is modular, and
individual filesystems are free to be case-sensitive or insensitive, and are usually
case-preserving. Some native filesystems have name length limits, which file and directory
names are silently truncated to fit. Scripts should be aware that the standard filesystem
currently has a name length limit of 10 characters, with up to 77 items in a directory,
but other filesystems may not impose such limitations.
Native filenames are of the form
Filesystem#Special_Field::DiskName.$.Directory.Directory.File
|
|
where
Special_Field is not usually present, but may contain . and $ .
Filesystem =~ m|[A-Za-z0-9_]|
DsicName =~ m|[A-Za-z0-9_/]|
$ represents the root directory
. is the path separator
@ is the current directory (per filesystem but machine global)
^ is the parent directory
Directory and File =~ m|[^\0- "\.\$\%\&:\@\\^\|\177]+|
|
|
The default filename translation is roughly tr|/.|./|;
Note that "ADFS::HardDisk.$.File" ne 'ADFS::HardDisk.$.File' and
that the second stage of $ interpolation in regular expressions will fall foul of
the $. if scripts are not careful.
Logical paths specified by system variables containing comma-separated search lists are
also allowed; hence System:Modules is a valid filename, and the filesystem will
prefix Modules with each section of System$Path until a name is made
that points to an object on disk. Writing to a new file System:Modules would be
allowed only if System$Path contains a single item list. The filesystem will also
expand system variables in filenames if enclosed in angle brackets, so <System$Dir>.Modules
would look for the file $ENV{'System$Dir'} . 'Modules'. The obvious
implication of this is that fully qualified filenames can start with <>
and should be protected when open is used for input.
Because . was in use as a directory separator and filenames could not be
assumed to be unique after 10 characters, Acorn implemented the C compiler to strip the
trailing .c .h .s and .o suffix from
filenames specified in source code and store the respective files in subdirectories named
after the suffix. Hence files are translated:
foo.h h.foo
C:foo.h C:h.foo (logical path variable)
sys/os.h sys.h.os (C compiler groks Unix-speak)
10charname.c c.10charname
10charname.o o.10charname
11charname_.c c.11charname (assuming filesystem truncates at 10)
|
|
The Unix emulation library's translation of filenames to native assumes that this sort of
translation is required, and it allows a user-defined list of known suffixes that it will
transpose in this fashion. This may seem transparent, but consider that with these rules foo/bar/baz.h
and foo/bar/h/baz both map to foo.bar.h.baz, and that readdir
and glob cannot and do not attempt to emulate the reverse mapping. Other .'s
in filenames are translated to /.
As implied above, the environment accessed through %ENV is global, and the
convention is that program specific environment variables are of the form Program$Name.
Each filesystem maintains a current directory, and the current filesystem's current directory
is the global current directory. Consequently, sociable programs don't change the
current directory but rely on full pathnames, and programs (and Makefiles) cannot assume that
they can spawn a child process which can change the current directory without affecting its
parent (and everyone else for that matter).
Because native operating system filehandles are global and are currently allocated down
from 255, with 0 being a reserved value, the Unix emulation library emulates Unix filehandles.
Consequently, you can't rely on passing STDIN, STDOUT, or STDERR
to your children.
The desire of users to express filenames of the form <Foo$Dir>.Bar on
the command line unquoted causes problems, too: `` command output capture has to
perform a guessing game. It assumes that a string <[^<>]+\$[^<>]>
is a reference to an environment variable, whereas anything else involving <
or > is redirection, and generally manages to be 99% right. Of course, the
problem remains that scripts cannot rely on any Unix tools being available, or that any tools
found have Unix-like command line arguments.
Extensions and XS are, in theory, buildable by anyone using free tools. In practice, many
don't, as users of the Acorn platform are used to binary distributions. MakeMaker does run,
but no available make currently copes with MakeMaker's makefiles; even if and when this should
be fixed, the lack of a Unix-like shell will cause problems with makefile rules, especially
lines of the form cd sdbm && make all, and anything using quoting.
"RISC OS" is the proper name for the operating system, but the value in $^O
is "riscos" (because we don't like shouting).
Perl has been ported to many platforms that do not fit into any of the categories listed
above. Some, such as AmigaOS, Atari MiNT, BeOS, HP MPE/iX, QNX, Plan 9, and VOS, have been
well-integrated into the standard Perl source code kit. You may need to see the ports/
directory on CPAN for information, and possibly binaries, for the likes of: aos, Atari ST,
lynxos, riscos, Novell Netware, Tandem Guardian, etc. (Yes, we know that some of these
OSes may fall under the Unix category, but we are not a standards body.)
Some approximate operating system names and their $^O values in the
"OTHER" category include:
OS $^O $Config{'archname'}
------------------------------------------
Amiga DOS amigaos m68k-amigos
BeOS beos
MPE/iX mpeix PA-RISC1.1
|
|
See also:
- Amiga, README.amiga (installed as perlamiga).
- Atari, README.mint and Guido Flohr's web page http://stud.uni-sb.de/~gufl0000/
- Be OS, README.beos
- HP 300 MPE/iX, README.mpeix and Mark Bixby's web page http://www.bixby.org/mark/perlix.html
- A free perl5-based PERL.NLM for Novell Netware is available in precompiled binary and
source code form from http://www.novell.com/ as well as from CPAN.
- Plan 9, README.plan9
|