<P>In most operating systems, lines in files are terminated by newlines.
Just what is used as a newline may vary from OS to OS. Unix
traditionally uses <CODE>\012</CODE>, one type of DOSish I/O uses <CODE>\015\012</CODE>,
and Mac OS uses <CODE>\015</CODE>.</P>
<P>Perl uses <CODE>\n</CODE> to represent the ``logical'' newline, where what is
logical may depend on the platform in use. In MacPerl, <CODE>\n</CODE> always
means <CODE>\015</CODE>. In DOSish perls, <CODE>\n</CODE> usually means <CODE>\012</CODE>, but
when accessing a file in ``text'' mode, STDIO translates it to (or
from) <CODE>\015\012</CODE>, depending on whether you're reading or writing.
Unix does the same thing on ttys in canonical mode. <CODE>\015\012</CODE>
is commonly referred to as CRLF.</P>
<P>Because of the ``text'' mode translation, DOSish perls have limitations
in using <A HREF="../../lib/Pod/perlfunc.html#item_seek"><CODE>seek</CODE></A> and <A HREF="../../lib/Pod/perlfunc.html#item_tell"><CODE>tell</CODE></A> on a file accessed in ``text'' mode.
Stick to <A HREF="../../lib/Pod/perlfunc.html#item_seek"><CODE>seek</CODE></A>-ing to locations you got from <A HREF="../../lib/Pod/perlfunc.html#item_tell"><CODE>tell</CODE></A> (and no
others), and you are usually free to use <A HREF="../../lib/Pod/perlfunc.html#item_seek"><CODE>seek</CODE></A> and <A HREF="../../lib/Pod/perlfunc.html#item_tell"><CODE>tell</CODE></A> even
in ``text'' mode. Using <A HREF="../../lib/Pod/perlfunc.html#item_seek"><CODE>seek</CODE></A> or <A HREF="../../lib/Pod/perlfunc.html#item_tell"><CODE>tell</CODE></A> or other file operations
may be non-portable. If you use <A HREF="#item_binmode"><CODE>binmode</CODE></A> on a file, however, you
can usually <A HREF="../../lib/Pod/perlfunc.html#item_seek"><CODE>seek</CODE></A> and <A HREF="../../lib/Pod/perlfunc.html#item_tell"><CODE>tell</CODE></A> with arbitrary values in safety.</P>
<P>A common misconception in socket programming is that <CODE>\n</CODE> eq <CODE>\012</CODE>
everywhere. When using protocols such as common Internet protocols,
<CODE>\012</CODE> and <CODE>\015</CODE> are called for specifically, and the values of
the logical <CODE>\n</CODE> and <CODE>\r</CODE> (carriage return) are not reliable.</P>
<P>When reading from a socket, remember that the default input record
separator <CODE>$/</CODE> is <CODE>\n</CODE>, but robust socket code will recognize as
either <CODE>\012</CODE> or <CODE>\015\012</CODE> as end of line:</P>
<PRE>
while (<SOCKET>) {
# ...
}</PRE>
<P>Because both CRLF and LF end in LF, the input record separator can
be set to LF and any CR stripped later. Better to write:</P>
<PRE>
use Socket qw(:DEFAULT :crlf);
local($/) = LF; # not needed if $/ is already \012</PRE>
<PRE>
while (<SOCKET>) {
s/$CR?$LF/\n/; # not sure if socket uses LF or CRLF, OK
# s/\015?\012/\n/; # same thing
}</PRE>
<P>This example is preferred over the previous one--even for Unix
platforms--because now any <CODE>\015</CODE>'s (<CODE>\cM</CODE>'s) are stripped out
(and there was much rejoicing).</P>
<P>Similarly, functions that return text data--such as a function that
fetches a web page--should sometimes translate newlines before
returning the data, if they've not yet been translated to the local
newline representation. A single line of code will often suffice:</P>
<PRE>
$data =~ s/\015?\012/\n/g;
return $data;</PRE>
<P>Some of this may be confusing. Here's a handy reference to the ASCII CR
and LF characters. You can print it out and stick it in your wallet.</P>
<PRE>
LF == \012 == \x0A == \cJ == ASCII 10
CR == \015 == \x0D == \cM == ASCII 13</PRE>
<PRE>
| Unix | DOS | Mac |
---------------------------
\n | LF | LF | CR |
\r | CR | CR | LF |
\n * | LF | CRLF | CR |
\r * | CR | CR | LF |
---------------------------
* text-mode STDIO</PRE>
<P>The Unix column assumes that you are not accessing a serial line
(like a tty) in canonical mode. If you are, then CR on input becomes
``\n'', and ``\n'' on output becomes CRLF.</P>
<P>These are just the most common definitions of <CODE>\n</CODE> and <CODE>\r</CODE> in Perl.
There may well be others.</P>
<P>
<H2><A NAME="numbers endianness and width">Numbers endianness and Width</A></H2>
<P>Different CPUs store integers and floating point numbers in different
orders (called <EM>endianness</EM>) and widths (32-bit and 64-bit being the
most common today). This affects your programs when they attempt to transfer
numbers in binary format from one CPU architecture to another,
usually either ``live'' via network connection, or by storing the
numbers to secondary storage such as a disk file or tape.</P>
<P>Conflicting storage orders make utter mess out of the numbers. If a
little-endian host (Intel, VAX) stores 0x12345678 (305419896 in
decimal), a big-endian host (Motorola, MIPS, Sparc, PA) reads it as
0x78563412 (2018915346 in decimal). To avoid this problem in network
(socket) connections use the <A HREF="../../lib/Pod/perlfunc.html#item_pack"><CODE>pack</CODE></A> and <A HREF="../../lib/Pod/perlfunc.html#item_unpack"><CODE>unpack</CODE></A> formats <CODE>n</CODE>
and <CODE>N</CODE>, the ``network'' orders. These are guaranteed to be portable.</P>
<P>You can explore the endianness of your platform by unpacking a
data structure packed in native format such as:</P>
<PRE>
print unpack("h*", pack("s2", 1, 2)), "\n";
# '10002000' on e.g. Intel x86 or Alpha 21064 in little-endian mode
# '00100020' on e.g. Motorola 68040</PRE>
<P>If you need to distinguish between endian architectures you could use
<P>The filesystem may support neither access timestamp nor change
timestamp (meaning that about the only portable timestamp is the
modification timestamp), or one second granularity of any timestamps
(e.g. the FAT filesystem limits the time granularity to two seconds).</P>
<P>VOS perl can emulate Unix filenames with <CODE>/</CODE> as path separator. The
native pathname characters greater-than, less-than, number-sign, and
percent-sign are always accepted.</P>
<P>RISC OS perl can emulate Unix filenames with <CODE>/</CODE> as path
separator, or go native and use <CODE>.</CODE> for path separator and <CODE>:</CODE> to
signal filesystems and disk names.</P>
<P>If all this is intimidating, have no (well, maybe only a little)
fear. There are modules that can help. The File::Spec modules
provide methods to do the Right Thing on whatever platform happens
to be running the program.</P>
<PRE>
use File::Spec::Functions;
chdir(updir()); # go up one directory
$file = catfile(curdir(), 'temp', 'file.txt');
# on Unix and Win32, './temp/file.txt'
# on Mac OS, ':temp:file.txt'
# on VMS, '[.temp]file.txt'</PRE>
<P>File::Spec is available in the standard distribution as of version
5.004_05. File::Spec::Functions is only in File::Spec 0.7 and later,
and some versions of perl come with version 0.6. If File::Spec
is not updated to 0.7 or later, you must use the object-oriented
interface from File::Spec (or upgrade File::Spec).</P>
<P>In general, production code should not have file paths hardcoded.
Making them user-supplied or read from a configuration file is
better, keeping in mind that file path syntax varies on different
machines.</P>
<P>This is especially noticeable in scripts like Makefiles and test suites,
which often assume <CODE>/</CODE> as a path separator for subdirectories.</P>
<P>Also of use is File::Basename from the standard distribution, which
splits a pathname into pieces (base filename, full path to directory,
and file suffix).</P>
<P>Even when on a single platform (if you can call Unix a single platform),
remember not to count on the existence or the contents of particular
system-specific files or directories, like <EM>/etc/passwd</EM>,
<EM>/etc/sendmail.conf</EM>, <EM>/etc/resolv.conf</EM>, or even <EM>/tmp/</EM>. For
example, <EM>/etc/passwd</EM> may exist but not contain the encrypted
passwords, because the system is using some form of enhanced security.
Or it may not contain all the accounts, because the system is using NIS.
If code does need to rely on such a file, include a description of the
file and its format in the code's documentation, then make it easy for
the user to override the default location of the file.</P>
<P>Don't assume a text file will end with a newline. They should,
but people forget.</P>
<P>Do not have two files of the same name with different case, like
<EM>test.pl</EM> and <EM>Test.pl</EM>, as many platforms have case-insensitive
filenames. Also, try not to have non-word characters (except for <CODE>.</CODE>)
in the names, and keep them to the 8.3 convention, for maximum
portability, onerous a burden though this may appear.</P>
<P>Likewise, when using the AutoSplit module, try to keep your functions to
8.3 naming and case-insensitive conventions; or, at the least,
make it so the resulting files have a unique (case-insensitively)
first 8 characters.</P>
<P>Whitespace in filenames is tolerated on most systems, but not all.
Many systems (DOS, VMS) cannot have more than one <CODE>.</CODE> in their filenames.</P>
<P>Don't assume <CODE>></CODE> won't be the first character of a filename.
Always use <CODE><</CODE> explicitly to open a file for reading,
unless you want the user to be able to specify a pipe open.</P>
<PRE>
open(FILE, "< $existing_file") or die $!;</PRE>
<P>If filenames might use strange characters, it is safest to open it
with <A HREF="#item_sysopen"><CODE>sysopen</CODE></A> instead of <A HREF="#item_open"><CODE>open</CODE></A>. <A HREF="#item_open"><CODE>open</CODE></A> is magic and can
translate characters like <CODE>></CODE>, <CODE><</CODE>, and <CODE>|</CODE>, which may
be the wrong thing to do. (Sometimes, though, it's the right thing.)</P>
<P>Not all platforms provide a command line. These are usually platforms
that rely primarily on a Graphical User Interface (GUI) for user
interaction. A program requiring a command line interface might
not work everywhere. This is probably for the user of the program
to deal with, so don't stay up late worrying about it.</P>
<P>Some platforms can't delete or rename files held open by the system.
Remember to <A HREF="../../lib/Pod/perlfunc.html#item_close"><CODE>close</CODE></A> files when you are done with them. Don't
<A HREF="../../lib/Pod/perlfunc.html#item_unlink"><CODE>unlink</CODE></A> or <A HREF="../../lib/Pod/perlfunc.html#item_rename"><CODE>rename</CODE></A> an open file. Don't <A HREF="../../lib/Pod/perlfunc.html#item_tie"><CODE>tie</CODE></A> or <A HREF="#item_open"><CODE>open</CODE></A> a
file already tied or opened; <A HREF="../../lib/Pod/perlfunc.html#item_untie"><CODE>untie</CODE></A> or <A HREF="../../lib/Pod/perlfunc.html#item_close"><CODE>close</CODE></A> it first.</P>
<P>Don't open the same file more than once at a time for writing, as some
operating systems put mandatory locks on such files.</P>
<P>Don't count on a specific environment variable existing in <CODE>%ENV</CODE>.
Don't count on <CODE>%ENV</CODE> entries being case-sensitive, or even
case-preserving.</P>
<P>Don't count on signals or <CODE>%SIG</CODE> for anything.</P>
<P>Don't count on filename globbing. Use <A HREF="../../lib/Pod/perlfunc.html#item_opendir"><CODE>opendir</CODE></A>, <A HREF="../../lib/Pod/perlfunc.html#item_readdir"><CODE>readdir</CODE></A>, and
<P>The value for <CODE>$offset</CODE> in Unix will be <CODE>0</CODE>, but in Mac OS will be
some large number. <CODE>$offset</CODE> can then be added to a Unix time value
to get what should be the proper value on any system.</P>
<P>
<H2><A NAME="character sets and character encoding">Character sets and character encoding</A></H2>
<P>Assume little about character sets. Assume nothing about
numerical values (<A HREF="../../lib/Pod/perlfunc.html#item_ord"><CODE>ord</CODE></A>, <A HREF="../../lib/Pod/perlfunc.html#item_chr"><CODE>chr</CODE></A>) of characters. Do not
assume that the alphabetic characters are encoded contiguously (in
the numeric sense). Do not assume anything about the ordering of the
characters. The lowercase letters may come before or after the
uppercase letters; the lowercase and uppercase may be interlaced so
that both `a' and `A' come before `b'; the accented and other
international characters may be interlaced so that ä comes
<P>As of version 5.002, Perl is built with a <CODE>$^O</CODE> variable that
indicates the operating system it was built on. This was implemented
to help speed up code that would otherwise have to <CODE>use Config</CODE>
and use the value of <CODE>$Config{osname}</CODE>. Of course, to get more
detailed information about the system, looking into <CODE>%Config</CODE> is
certainly recommended.</P>
<P><CODE>%Config</CODE> 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.</P>
<P>
<H2><A NAME="unix">Unix</A></H2>
<P>Perl works on a bewildering variety of Unix and Unix-like platforms (see
e.g. most of the files in the <EM>hints/</EM> directory in the source code kit).
On most of these systems, the value of <CODE>$^O</CODE> (hence <CODE>$Config{'osname'}</CODE>,
too) is determined either by lowercasing and stripping punctuation from the
first field of the string returned by typing <CODE>uname -a</CODE> (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:</P>
<PRE>
uname $^O $Config{'archname'}
--------------------------------------------
AIX aix aix
BSD/OS bsdos i386-bsdos
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 rhapsody rhapsody
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</PRE>
<P>Because the value of <CODE>$Config{archname}</CODE> may depend on the
hardware architecture, it can vary more than the value of <CODE>$^O</CODE>.</P>
<P>
<H2><A NAME="dos and derivatives">DOS and Derivatives</A></H2>
<P>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 <EM>COMMAND.COM</EM> or <EM>CMD.EXE</EM> style shells should
be aware that each of these file specifications may have subtle
differences:</P>
<PRE>
$filespec0 = "c:/foo/bar/file.txt";
$filespec1 = "c:\\foo\\bar\\file.txt";
$filespec2 = 'c:\foo\bar\file.txt';
$filespec3 = 'c:\\foo\\bar\\file.txt';</PRE>
<P>System calls accept either <CODE>/</CODE> or <CODE>\</CODE> as the path separator.
However, many command-line utilities of DOS vintage treat <CODE>/</CODE> as
the option prefix, so may get confused by filenames containing <CODE>/</CODE>.
Aside from calling any external programs, <CODE>/</CODE> 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.</P>
<P>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 <A HREF="../../lib/Pod/perlfunc.html#item_readdir"><CODE>readdir</CODE></A> or used with functions like <A HREF="#item_open"><CODE>open</CODE></A> or <A HREF="../../lib/Pod/perlfunc.html#item_opendir"><CODE>opendir</CODE></A>.</P>
<P>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.</P>
<P>Users of these operating systems may also wish to make use of
scripts such as <EM>pl2bat.bat</EM> or <EM>pl2cmd</EM> to
put wrappers around your scripts.</P>
<P>Newline (<CODE>\n</CODE>) is translated as <CODE>\015\012</CODE> by STDIO when reading from
and writing to files (see <A HREF="#newlines">Newlines</A>). <A HREF="#item_binmode"><CODE>binmode(FILEHANDLE)</CODE></A>
will keep <CODE>\n</CODE> translated as <CODE>\012</CODE> for that filehandle. Since it is a
no-op on other systems, <A HREF="#item_binmode"><CODE>binmode</CODE></A> 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.</P>
<P>The <CODE>$^O</CODE> variable and the <CODE>$Config{archname}</CODE> values for various
DOSish perls are as follows:</P>
<PRE>
OS $^O $Config{'archname'}
--------------------------------------------
MS-DOS dos
PC-DOS dos
OS/2 os2
Windows 95 MSWin32 MSWin32-x86
Windows 98 MSWin32 MSWin32-x86
Windows NT MSWin32 MSWin32-x86
Windows NT MSWin32 MSWin32-ALPHA
Windows NT MSWin32 MSWin32-ppc
Cygwin cygwin</PRE>
<P>Also see:</P>
<UL>
<LI>
The djgpp environment for DOS, <A HREF="http://www.delorie.com/djgpp/">http://www.delorie.com/djgpp/</A>
and <A HREF="../../lib/Pod/perldos.html">the perldos manpage</A>.
<P></P>
<LI>
The EMX environment for DOS, OS/2, etc. <A HREF="mailto:emx@iaehv.nl,">emx@iaehv.nl,</A>
<A HREF="http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/index.html">http://www.leo.org/pub/comp/os/os2/leo/gnu/emx+gcc/index.html</A> or
<A HREF="ftp://hobbes.nmsu.edu/pub/os2/dev/emx.">ftp://hobbes.nmsu.edu/pub/os2/dev/emx.</A> Also <A HREF="../../lib/Pod/perlos2.html">the perlos2 manpage</A>.
<P></P>
<LI>
Build instructions for Win32 in <A HREF="../../lib/Pod/perlwin32.html">the perlwin32 manpage</A>, or under the Cygnus environment
in <A HREF="../../lib/Pod/perlcygwin.html">the perlcygwin manpage</A>.
<P></P>
<LI>
The <CODE>Win32::*</CODE> modules in <A HREF="../../lib/Pod/Win32.html">the Win32 manpage</A>.
<P></P>
<LI>
The ActiveState Pages, <A HREF="http://www.activestate.com/">http://www.activestate.com/</A>
<P></P>
<LI>
The Cygwin environment for Win32; <EM>README.cygwin</EM> (installed
as <A HREF="../../lib/Pod/perlcygwin.html">the perlcygwin manpage</A>), <A HREF="http://sourceware.cygnus.com/cygwin/">http://sourceware.cygnus.com/cygwin/</A>
<P></P>
<LI>
The U/WIN environment for Win32,
<http://www.research.att.com/sw/tools/uwin/
<P></P>
<DT><STRONG><A NAME="item_Build_instructions_for_OS%2F2%2C_perlos2">Build instructions for OS/2, <A HREF="../../lib/Pod/perlos2.html">the perlos2 manpage</A></A></STRONG><BR>
<DD>
</UL>
<P>
<H2><A NAME="mac os">Mac OS</A></H2>
<P>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.</P>
<P>Directories are specified as:</P>
<PRE>
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</PRE>
<P>Files are stored in the directory in alphabetical order. Filenames are
limited to 31 characters, and may include any character except for
null and <CODE>:</CODE>, which is reserved as the path separator.</P>
<P>Instead of <A HREF="#item_flock"><CODE>flock</CODE></A>, see <CODE>FSpSetFLock</CODE> and <CODE>FSpRstFLock</CODE> in the
Mac::Files module, or <A HREF="#item_chmod"><CODE>chmod(0444, ...)</CODE></A> and <A HREF="#item_chmod"><CODE>chmod(0666, ...)</CODE></A>.</P>
<P>In the MacPerl application, you can't run a program from the command line;
programs that expect <CODE>@ARGV</CODE> to be populated can be edited with something
like the following, which brings up a dialog box asking for the command
line arguments.</P>
<PRE>
if (!@ARGV) {
@ARGV = split /\s+/, MacPerl::Ask('Arguments?');
}</PRE>
<P>A MacPerl script saved as a ``droplet'' will populate <CODE>@ARGV</CODE> with the full
pathnames of the files dropped onto the script.</P>
<P>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:</P>
<PRE>
perl myscript.plx some arguments</PRE>
<P>ToolServer is another app from Apple that provides access to MPW tools
from MPW and the MacPerl app, which allows MacPerl programs to use
<A HREF="#item_system"><CODE>system</CODE></A>, backticks, and piped <A HREF="#item_open"><CODE>open</CODE></A>.</P>
<P>``Mac OS'' is the proper name for the operating system, but the value
in <CODE>$^O</CODE> is ``MacOS''. To determine architecture, version, or whether
the application or MPW tool version is running, check:</P>
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]+|</PRE>
<P>The default filename translation is roughly <CODE>tr|/.|./|;</CODE></P>
<P>Note that <CODE>"ADFS::HardDisk.$.File" ne 'ADFS::HardDisk.$.File'</CODE> and that
the second stage of <CODE>$</CODE> interpolation in regular expressions will fall
foul of the <CODE>$.</CODE> if scripts are not careful.</P>
<P>Logical paths specified by system variables containing comma-separated
search lists are also allowed; hence <CODE>System:Modules</CODE> is a valid
filename, and the filesystem will prefix <CODE>Modules</CODE> with each section of
<CODE>System$Path</CODE> until a name is made that points to an object on disk.
Writing to a new file <CODE>System:Modules</CODE> would be allowed only if
<CODE>System$Path</CODE> contains a single item list. The filesystem will also
expand system variables in filenames if enclosed in angle brackets, so
<CODE><System$Dir>.Modules</CODE> would look for the file
<CODE>$ENV{'System$Dir'} . 'Modules'</CODE>. The obvious implication of this is
that <STRONG>fully qualified filenames can start with <CODE><></CODE></STRONG> and should
be protected when <A HREF="#item_open"><CODE>open</CODE></A> is used for input.</P>
<P>Because <CODE>.</CODE> 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 <CODE>.c</CODE> <CODE>.h</CODE> <CODE>.s</CODE> and <CODE>.o</CODE> suffix from
filenames specified in source code and store the respective files in
subdirectories named after the suffix. Hence files are translated:</P>
<PRE>
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)</PRE>
<P>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 <CODE>foo/bar/baz.h</CODE>
and <CODE>foo/bar/h/baz</CODE> both map to <CODE>foo.bar.h.baz</CODE>, and that <A HREF="../../lib/Pod/perlfunc.html#item_readdir"><CODE>readdir</CODE></A> and
<A HREF="#item_glob"><CODE>glob</CODE></A> cannot and do not attempt to emulate the reverse mapping. Other
<CODE>.</CODE>'s in filenames are translated to <CODE>/</CODE>.</P>
<P>As implied above, the environment accessed through <CODE>%ENV</CODE> is global, and
the convention is that program specific environment variables are of the
form <CODE>Program$Name</CODE>. Each filesystem maintains a current directory,
and the current filesystem's current directory is the <STRONG>global</STRONG> 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).</P>
<P>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 <CODE>STDIN</CODE>, <CODE>STDOUT</CODE>, or <CODE>STDERR</CODE> to your children.</P>
<P>The desire of users to express filenames of the form
<CODE><Foo$Dir>.Bar</CODE> on the command line unquoted causes problems,
too: <CODE>``</CODE> command output capture has to perform a guessing game. It
assumes that a string <CODE><[^<>]+\$[^<>]></CODE> is a
reference to an environment variable, whereas anything else involving
<CODE><</CODE> or <CODE>></CODE> 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.</P>
<P>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 <CODE>cd
sdbm && make all</CODE>, and anything using quoting.</P>
<P>``RISC OS'' is the proper name for the operating system, but the value
in <CODE>$^O</CODE> is ``riscos'' (because we don't like shouting).</P>
<P>
<H2><A NAME="other perls">Other perls</A></H2>
<P>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
<EM>ports/</EM> directory on CPAN for information, and possibly binaries,
for the likes of: aos, Atari ST, lynxos, riscos, Novell Netware,
Tandem Guardian, <EM>etc.</EM> (Yes, we know that some of these OSes may
fall under the Unix category, but we are not a standards body.)</P>
<P>Some approximate operating system names and their <CODE>$^O</CODE> values
in the ``OTHER'' category include:</P>
<PRE>
OS $^O $Config{'archname'}
------------------------------------------
Amiga DOS amigaos m68k-amigos
MPE/iX mpeix PA-RISC1.1</PRE>
<P>See also:</P>
<UL>
<LI>
Amiga, <EM>README.amiga</EM> (installed as <A HREF="../../lib/Pod/perlamiga.html">the perlamiga manpage</A>).
<P></P>
<LI>
Atari, <EM>README.mint</EM> and Guido Flohr's web page
<CODE>-r</CODE>, <CODE>-w</CODE>, and <CODE>-x</CODE> have a limited meaning only; directories
and applications are executable, and there are no uid/gid
considerations. <CODE>-o</CODE> is not supported. (Mac OS)
<P><CODE>-r</CODE>, <CODE>-w</CODE>, <CODE>-x</CODE>, and <CODE>-o</CODE> tell whether the file is accessible,
which may not reflect UIC-based file protections. (VMS)</P>
<P><CODE>-s</CODE> returns the size of the data fork, not the total size of data fork
plus resource fork. (Mac OS).</P>
<P><CODE>-s</CODE> by name on an open file will return the space reserved on disk,
rather than the current extent. <CODE>-s</CODE> on an open filehandle returns the
current size. (RISC OS)</P>
<P><CODE>-R</CODE>, <CODE>-W</CODE>, <A HREF="#item_%2DX"><CODE>-X</CODE></A>, <CODE>-O</CODE> are indistinguishable from <CODE>-r</CODE>, <CODE>-w</CODE>,
Only implemented if ToolServer is installed. (Mac OS)
<P>As an optimization, may not call the command shell specified in
<CODE>$ENV{PERL5SHELL}</CODE>. <A HREF="#item_system"><CODE>system(1, @args)</CODE></A> spawns an external
process and immediately returns its process designator, without
waiting for it to terminate. Return value may be used subsequently
in <A HREF="#item_wait"><CODE>wait</CODE></A> or <A HREF="#item_waitpid"><CODE>waitpid</CODE></A>. Failure to <CODE>spawn()</CODE> a subprocess is indicated
by setting $? to ``255 << 8''. <CODE>$?</CODE> is set in a way compatible with
Unix (i.e. the exitstatus of the subprocess is obtained by ``$? >> 8'',
as described in the documentation). (Win32)</P>
<P>There is no shell to process metacharacters, and the native standard is
to pass a command line terminated by ``\n'' ``\r'' or ``\0'' to the spawned
program. Redirection such as <CODE>> foo</CODE> is performed (if at all) by
the run time library of the spawned program. <A HREF="#item_system"><CODE>system</CODE></A> <EM>list</EM> will call
the Unix emulation library's <A HREF="#item_exec"><CODE>exec</CODE></A> emulation, which attempts to provide
emulation of the stdin, stdout, stderr in force in the parent, providing
the child program uses a compatible version of the emulation library.
<EM>scalar</EM> will call the native command line direct and no such emulation
of a child Unix program will exists. Mileage <STRONG>will</STRONG> vary. (RISC OS)</P>
<P>Far from being POSIX compliant. Because there may be no underlying
/bin/sh tries to work around the problem by forking and execing the
first token in its argument string. Handles basic redirection
(``<'' or ``>'') on its own behalf. (MiNT)</P>
<P>Does not automatically flush output handles on some platforms.