⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perlport.pod

📁 ARM上的如果你对底层感兴趣
💻 POD
📖 第 1 页 / 共 4 页
字号:


=head2 Character sets and character encoding

Assume very little about character sets.  Do not assume anything about
the numerical values (C<ord()>, C<chr()>) of characters.  Do not
assume that the alphabetic characters are encoded contiguously (in
numerical sense).  Do no 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 the 'b', the accented and other
international characters may be interlaced so that E<auml> comes
before the 'b'.


=head2 Internationalisation

If you may assume POSIX (a rather large assumption, that: in practise
that means UNIX) you may read more about the POSIX locale system from
L<perllocale>.  The locale system at least attempts to make things a
little bit more portable or at least more convenient and
native-friendly for non-English users.  The system affects character
sets and encoding, and date and time formatting, among other things.


=head2 System Resources

If your code is destined for systems with severely constrained (or
missing!) virtual memory systems then you want to be I<especially> mindful
of avoiding wasteful constructs such as:

    # NOTE: this is no longer "bad" in perl5.005
    for (0..10000000) {}                       # bad
    for (my $x = 0; $x <= 10000000; ++$x) {}   # good

    @lines = <VERY_LARGE_FILE>;                # bad

    while (<FILE>) {$file .= $_}               # sometimes bad
    $file = join('', <FILE>);                  # better

The last two may appear unintuitive to most people.  The first of those
two constructs repeatedly grows a string, while the second allocates a
large chunk of memory in one go.  On some systems, the latter is more
efficient that the former.


=head2 Security

Most multi-user platforms provide basic levels of security that is usually
felt at the file-system level.  Other platforms usually don't
(unfortunately).  Thus the notion of user id, or "home" directory, or even
the state of being logged-in, may be unrecognizable on many platforms.  If
you write programs that are security conscious, it is usually best to know
what type of system you will be operating under, and write code explicitly
for that platform (or class of platforms).


=head2 Style

For those times when it is necessary to have platform-specific code,
consider keeping the platform-specific code in one place, making porting
to other platforms easier.  Use the C<Config> module and the special
variable C<$^O> to differentiate platforms, as described in
L<"PLATFORMS">.


=head1 CPAN Testers

Modules uploaded to CPAN are tested by a variety of volunteers on
different platforms.  These CPAN testers are notified by mail of each
new upload, and reply to the list with PASS, FAIL, NA (not applicable to
this platform), or UNKNOWN (unknown), along with any relevant notations.

The purpose of the testing is twofold: one, to help developers fix any
problems in their code that crop up because of lack of testing on other
platforms; two, to provide users with information about whether or not
a given module works on a given platform.

=over 4

=item Mailing list: cpan-testers@perl.org

=item Testing results: C<http://www.connect.net/gbarr/cpan-test/>

=back


=head1 PLATFORMS

As of version 5.002, Perl is built with a C<$^O> variable that
indicates the operating system it was built on.  This was implemented
to help speed up code that would otherwise have to C<use Config;> and
use the value of C<$Config{'osname'}>.  Of course, to get
detailed information about the system, looking into C<%Config> is
certainly recommended.

=head2 Unix

Perl works on a bewildering variety of Unix and Unix-like platforms (see
e.g. most of the files in the F<hints/> directory in the source code kit).
On most of these systems, the value of C<$^O> (hence C<$Config{'osname'}>,
too) is determined by lowercasing and stripping punctuation from the first
field of the string returned by typing C<uname -a> (or a similar command)
at the shell prompt.  Here, for example, are a few of the more popular
Unix flavors:

    uname        $^O        $Config{'archname'}
    -------------------------------------------
    AIX          aix        aix
    FreeBSD      freebsd    freebsd-i386    
    Linux        linux      i386-linux
    HP-UX        hpux       PA-RISC1.1
    IRIX	 irix       irix
    OSF1         dec_osf    alpha-dec_osf
    SunOS        solaris    sun4-solaris
    SunOS        solaris    i86pc-solaris
    SunOS4       sunos      sun4-sunos

Note that because the C<$Config{'archname'}> may depend on the hardware
architecture it may vary quite a lot, much more than the C<$^O>.

=head2 DOS and Derivatives

Perl has long been ported to PC 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 I<COMMAND.COM> and/or I<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 C</> or C<\> as the path separator.  However,
many command-line utilities of DOS vintage treat C</> as the option
prefix, so they may get confused by filenames containing C</>.  Aside
from calling any external programs, C</> 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 only accommodate "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 C<readdir> or used with functions like C<open> or C<opendir>.

DOS also treats several filenames as special, such as AUX, PRN, NUL, CON,
COM1, LPT1, LPT2 etc.  Unfortunately these filenames won't even work
if you include an explicit directory prefix, in some cases.  It is best
to avoid such filenames, if you want your code to be portable to DOS
and its derivatives.

Users of these operating systems may also wish to make use of
scripts such as I<pl2bat.bat> or I<pl2cmd> as appropriate to
put wrappers around your scripts.

Newline (C<\n>) is translated as C<\015\012> by STDIO when reading from
and writing to files.  C<binmode(FILEHANDLE)> will keep C<\n> translated
as C<\012> for that filehandle.  Since it is a noop on other systems,
C<binmode> should be used for cross-platform code that deals with binary
data.

The C<$^O> variable and the C<$Config{'archname'}> values for various
DOSish perls are as follows:

    OS            $^O        $Config{'archname'}
    --------------------------------------------
    MS-DOS        dos
    PC-DOS        dos
    OS/2          os2
    Windows 95    MSWin32    MSWin32-x86
    Windows NT    MSWin32    MSWin32-x86
    Windows NT    MSWin32    MSWin32-alpha
    Windows NT    MSWin32    MSWin32-ppc

Also see:

=over 4

=item The djgpp environment for DOS, C<http://www.delorie.com/djgpp/>

=item The EMX environment for DOS, OS/2, etc. C<emx@iaehv.nl>,
C<http://www.juge.com/bbs/Hobb.19.html>

=item Build instructions for Win32, L<perlwin32>.

=item The ActiveState Pages, C<http://www.activestate.com/>

=back


=head2 S<Mac OS>

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.  See I<MacPerl: Power and Ease> and L<"CPAN Testers">
for more details.

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 in a directory are stored in alphabetical order.  Filenames are
limited to 31 characters, and may include any character except C<:>,
which is reserved as a path separator.

Instead of C<flock>, see C<FSpSetFLock> and C<FSpRstFLock> in the
C<Mac::Files> module.

In the MacPerl application, you can't run a program from the command line;
programs that expect C<@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 C<@ARGV> with the full
pathnames of the files dropped onto the script.

Mac users can use programs on a kind of command line 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
C<system>, backticks, and piped C<open>.

"S<Mac OS>" is the proper name for the operating system, but the value
in C<$^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';

S<Mac OS X>, to be based on NeXT's OpenStep OS, will be able to run
MacPerl natively (in the Blue Box, and even in the Yellow Box, once some
changes to the toolbox calls are made), but Unix perl will also run
natively.

Also see:

=over 4

=item The MacPerl Pages, C<http://www.ptf.com/macperl/>.

=item The MacPerl mailing list, C<mac-perl-request@iis.ee.ethz.ch>.

=back


=head2 VMS

Perl on VMS is discussed in F<vms/perlvms.pod> in the perl distribution.
Note that 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 a number of 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 C<$ ASSIGN/nolog/user SYS$COMMAND: SYS$INPUT> if your
perl-in-DCL script expects to do things like C<$read = E<lt>STDINE<gt>;>.

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 C</[A-Z0-9$_-]/>.

VMS' RMS filesystem is case insensitive and does not preserve case.
C<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 C<readdir> with a file named F<A.;5>
will return F<a.> (though that file could be opened with
C<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
C<PERL_ROOT:[LIB.2.3.4.5.6.7.8]> is a valid directory specification but
C<PERL_ROOT:[LIB.2.3.4.5.6.7.8.9]> is not.  F<Makefile.PL> authors might
have to take this into account, but at least they can refer to the former
as C</PERL_ROOT/lib/2/3/4/5/6/7/8/>.

The C<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 C<\n> represents depends on the type of file that is open.  It could
be C<\015>, C<\012>, C<\015\012>, or nothing.  Reading from a file
translates newlines to C<\012>, unless C<binmode> was executed on that
handle, just like DOSish perls.

TCP/IP stacks are optional on VMS, so socket routines might not be
implemented.  UDP sockets may not be supported.

The value of C<$^O> on OpenVMS is "VMS".  To determine the architecture
that you are running on without resorting to loading all of C<%Config>
you can examine the content of the C<@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";
    }

Also see:

=over 4

=item L<perlvms.pod>

=item vmsperl list, C<vmsperl-request@newman.upenn.edu>

Put words C<SUBSCRIBE VMSPERL> in message body.

=item vmsperl on the web, C<http://www.sidhe.org/vmsperl/index.html>

=back


=head2 EBCDIC Platforms

Recent versions of Perl have been ported to platforms such as OS/400 on

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -