perlport.pod

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 1,586 行 · 第 1/5 页

POD
1,586
字号
    require Time::Local;    $offset = Time::Local::timegm(0, 0, 0, 1, 0, 70);The value for C<$offset> in Unix will be C<0>, but in Mac OS will besome large number.  C<$offset> can then be added to a Unix time valueto get what should be the proper value on any system.On Windows (at least), you shouldn't pass a negative value to C<gmtime> orC<localtime>.=head2 Character sets and character encodingAssume very little about character sets.Assume nothing about numerical values (C<ord>, C<chr>) of characters.Do not use explicit code point ranges (like \xHH-\xHH); use forexample symbolic character classes like C<[:print:]>.Do not assume that the alphabetic characters are encoded contiguously(in the numeric sense).  There may be gaps.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 maybe interlaced so that E<auml> comes before "b".=head2 InternationalisationIf you may assume POSIX (a rather large assumption), you may readmore about the POSIX locale system from L<perllocale>.  The localesystem at least attempts to make things a little bit more portable,or at least more convenient and native-friendly for non-Englishusers.  The system affects character sets and encoding, and dateand time formatting--amongst other things.If you really want to be international, you should consider Unicode.See L<perluniintro> and L<perlunicode> for more information.If you want to use non-ASCII bytes (outside the bytes 0x00..0x7f) inthe "source code" of your code, to be portable you have to be explicitabout what bytes they are.  Someone might for example be using yourcode under a UTF-8 locale, in which case random native bytes might beillegal ("Malformed UTF-8 ...")  This means that for example embeddingISO 8859-1 bytes beyond 0x7f into your strings might cause troublelater.  If the bytes are native 8-bit bytes, you can use the C<bytes>pragma.  If the bytes are in a string (regular expression being acurious string), you can often also use the C<\xHH> notation insteadof embedding the bytes as-is.  (If you want to write your code in UTF-8,you can use the C<utf8>.) The C<bytes> and C<utf8> pragmata areavailable since Perl 5.6.0.=head2 System ResourcesIf your code is destined for systems with severely constrained (ormissing!) virtual memory systems then you want to be I<especially> mindfulof 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>);                  # betterThe last two constructs may appear unintuitive to most people.  Thefirst repeatedly grows a string, whereas the second allocates alarge chunk of memory in one go.  On some systems, the second ismore efficient that the first.=head2 SecurityMost multi-user platforms provide basic levels of security, usuallyimplemented at the filesystem level.  Some, however, donot-- unfortunately.  Thus the notion of user id, or "home" directory,or even the state of being logged-in, may be unrecognizable on manyplatforms.  If you write programs that are security-conscious, itis usually best to know what type of system you will be runningunder so that you can write code explicitly for that platform (orclass of platforms).Don't assume the UNIX filesystem access semantics: the operatingsystem or the filesystem may be using some ACL systems, which arericher languages than the usual rwx.  Even if the rwx exist,their semantics might be different.(From security viewpoint testing for permissions before attempting todo something is silly anyway: if one tries this, there is potentialfor race conditions-- someone or something might change thepermissions between the permissions check and the actual operation.Just try the operation.)Don't assume the UNIX user and group semantics: especially, don'texpect the C<< $< >> and C<< $> >> (or the C<$(> and C<$)>) to workfor switching identities (or memberships).Don't assume set-uid and set-gid semantics. (And even if you do,think twice: set-uid and set-gid are a known can of security worms.)=head2 StyleFor those times when it is necessary to have platform-specific code,consider keeping the platform-specific code in one place, making portingto other platforms easier.  Use the Config module and the specialvariable C<$^O> to differentiate platforms, as described inL<"PLATFORMS">.Be careful in the tests you supply with your module or programs.Module code may be fully portable, but its tests might not be.  Thisoften happens when tests spawn off other processes or call externalprograms to aid in the testing, or when (as noted above) the testsassume certain things about the filesystem and paths.  Be careful notto depend on a specific output style for errors, such as when checkingC<$!> after a failed system call.  Using C<$!> for anything else thandisplaying it as output is doubtful (though see the Errno module fortesting reasonably portably for error value). Some platforms expecta certain output format, and Perl on those platforms may have beenadjusted accordingly.  Most specifically, don't anchor a regex whentesting an error value.=head1 CPAN TestersModules uploaded to CPAN are tested by a variety of volunteers ondifferent platforms.  These CPAN testers are notified by mail of eachnew upload, and reply to the list with PASS, FAIL, NA (not applicable tothis platform), or UNKNOWN (unknown), along with any relevant notations.The purpose of the testing is twofold: one, to help developers fix anyproblems in their code that crop up because of lack of testing on otherplatforms; two, to provide users with information about whethera given module works on a given platform.Also see: =over 4=item *Mailing list: cpan-testers@perl.org=item *Testing results: http://testers.cpan.org/=back=head1 PLATFORMSAs of version 5.002, Perl is built with a C<$^O> variable thatindicates the operating system it was built on.  This was implementedto help speed up code that would otherwise have to C<use Config>and use the value of C<$Config{osname}>.  Of course, to get moredetailed information about the system, looking into C<%Config> iscertainly recommended.C<%Config> cannot always be trusted, however, because it was builtat compile time.  If perl was built in one place, then transferredelsewhere, some values may be wrong.  The values may even have beenedited after the fact.=head2 UnixPerl works on a bewildering variety of Unix and Unix-like platforms (seee.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 either by lowercasing and stripping punctuation from thefirst field of the string returned by typing C<uname -a> (or a similar command)at the shell prompt or by testing the file system for the presence ofuniquely 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-sunosBecause the value of C<$Config{archname}> may depend on thehardware architecture, it can vary more than the value of C<$^O>.=head2 DOS and DerivativesPerl has long been ported to Intel-style microcomputers running undersystems like PC-DOS, MS-DOS, OS/2, and most Windows platforms you canbring yourself to mention (except for Windows CE, if you count that).Users familiar with I<COMMAND.COM> or I<CMD.EXE> style shells shouldbe aware that each of these file specifications may have subtledifferences:    $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</> asthe option prefix, so 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 whatnot to.The DOS FAT filesystem can accommodate only "8.3" style filenames.  Underthe "case-insensitive, but case-preserving" HPFS (OS/2) and NTFS (NT)filesystems you may have to be careful about case returned with functionslike 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, sometimes thesefilenames won't even work if you include an explicit directoryprefix.  It is best to avoid such filenames, if you want your codeto be portable to DOS and its derivatives.  It's hard to know whatthese all are, unfortunately.Users of these operating systems may also wish to make use ofscripts such as I<pl2bat.bat> or I<pl2cmd> toput wrappers around your scripts.Newline (C<\n>) is translated as C<\015\012> by STDIO when reading fromand writing to files (see L<"Newlines">).  C<binmode(FILEHANDLE)>will keep C<\n> translated as C<\012> for that filehandle.  Since it is ano-op on other systems, C<binmode> should be used for cross-platform codethat deals with binary data.  That's assuming you realize in advancethat your data is in binary.  General-purpose programs shouldoften assume nothing about their data.The C<$^O> variable and the C<$Config{archname}> values for variousDOSish 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 00     Windows XP    MSWin32    MSWin32-x86       2      5 01     Windows 2003  MSWin32    MSWin32-x86       2      5 02     Windows CE    MSWin32    ?                 3                Cygwin        cygwin     cygwinThe various MSWin32 Perl's can distinguish the OS they are running onvia 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 C<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)|x86Also see:=over 4=item *The djgpp environment for DOS, http://www.delorie.com/djgpp/and L<perldos>.=item *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 orftp://hobbes.nmsu.edu/pub/os2/dev/emx/  Also L<perlos2>.=item *Build instructions for Win32 in L<perlwin32>, or under the Cygnus environmentin L<perlcygwin>.  =item *The C<Win32::*> modules in L<Win32>.=item *The ActiveState Pages, http://www.activestate.com/=item *

⌨️ 快捷键说明

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