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

📄 perl5004delta.pod

📁 MSYS在windows下模拟了一个类unix的终端
💻 POD
📖 第 1 页 / 共 4 页
字号:
=head1 NAMEperldelta - what's new for perl5.004=head1 DESCRIPTIONThis document describes differences between the 5.003 release (asdocumented in I<Programming Perl>, second edition--the Camel Book) andthis one.=head1 Supported EnvironmentsPerl5.004 builds out of the box on Unix, Plan 9, LynxOS, VMS, OS/2,QNX, AmigaOS, and Windows NT.  Perl runs on Windows 95 as well, but itcannot be built there, for lack of a reasonable command interpreter.=head1 Core ChangesMost importantly, many bugs were fixed, including several securityproblems.  See the F<Changes> file in the distribution for details.=head2 List assignment to %ENV worksC<%ENV = ()> and C<%ENV = @list> now work as expected (except on VMSwhere it generates a fatal error).=head2 Change to "Can't locate Foo.pm in @INC" errorThe error "Can't locate Foo.pm in @INC" now lists the contents of @INCfor easier debugging.=head2 Compilation option: Binary compatibility with 5.003There is a new Configure question that asks if you want to maintainbinary compatibility with Perl 5.003.  If you choose binarycompatibility, you do not have to recompile your extensions, but youmight have symbol conflicts if you embed Perl in another application,just as in the 5.003 release.  By default, binary compatibilityis preserved at the expense of symbol table pollution.=head2 $PERL5OPT environment variableYou may now put Perl options in the $PERL5OPT environment variable.Unless Perl is running with taint checks, it will interpret thisvariable as if its contents had appeared on a "#!perl" line at thebeginning of your script, except that hyphens are optional.  PERL5OPTmay only be used to set the following switches: B<-[DIMUdmw]>.=head2 Limitations on B<-M>, B<-m>, and B<-T> optionsThe C<-M> and C<-m> options are no longer allowed on the C<#!> line ofa script.  If a script needs a module, it should invoke it with theC<use> pragma.The B<-T> option is also forbidden on the C<#!> line of a script,unless it was present on the Perl command line.  Due to the way C<#!>works, this usually means that B<-T> must be in the first argument.Thus:    #!/usr/bin/perl -T -wwill probably work for an executable script invoked as C<scriptname>,while:    #!/usr/bin/perl -w -Twill probably fail under the same conditions.  (Non-Unix systems willprobably not follow this rule.)  But C<perl scriptname> is guaranteedto fail, since then there is no chance of B<-T> being found on thecommand line before it is found on the C<#!> line.=head2 More precise warningsIf you removed the B<-w> option from your Perl 5.003 scripts because itmade Perl too verbose, we recommend that you try putting it back whenyou upgrade to Perl 5.004.  Each new perl version tends to remove someundesirable warnings, while adding new warnings that may catch bugs inyour scripts.=head2 Deprecated: Inherited C<AUTOLOAD> for non-methodsBefore Perl 5.004, C<AUTOLOAD> functions were looked up as methods(using the C<@ISA> hierarchy), even when the function to be autoloadedwas called as a plain function (e.g. C<Foo::bar()>), not a method(e.g. C<< Foo->bar() >> or C<< $obj->bar() >>).Perl 5.005 will use method lookup only for methods' C<AUTOLOAD>s.However, there is a significant base of existing code that may be usingthe old behavior.  So, as an interim step, Perl 5.004 issues an optionalwarning when a non-method uses an inherited C<AUTOLOAD>.The simple rule is:  Inheritance will not work when autoloadingnon-methods.  The simple fix for old code is:  In any module that used todepend on inheriting C<AUTOLOAD> for non-methods from a base class namedC<BaseClass>, execute C<*AUTOLOAD = \&BaseClass::AUTOLOAD> during startup.=head2 Previously deprecated %OVERLOAD is no longer usableUsing %OVERLOAD to define overloading was deprecated in 5.003.Overloading is now defined using the overload pragma. %OVERLOAD isstill used internally but should not be used by Perl scripts. SeeL<overload> for more details.=head2 Subroutine arguments created only when they're modifiedIn Perl 5.004, nonexistent array and hash elements used as subroutineparameters are brought into existence only if they are actuallyassigned to (via C<@_>).Earlier versions of Perl vary in their handling of such arguments.Perl versions 5.002 and 5.003 always brought them into existence.Perl versions 5.000 and 5.001 brought them into existence only ifthey were not the first argument (which was almost certainly a bug).Earlier versions of Perl never brought them into existence.For example, given this code:     undef @a; undef %a;     sub show { print $_[0] };     sub change { $_[0]++ };     show($a[2]);     change($a{b});After this code executes in Perl 5.004, $a{b} exists but $a[2] doesnot.  In Perl 5.002 and 5.003, both $a{b} and $a[2] would have existed(but $a[2]'s value would have been undefined).=head2 Group vector changeable with C<$)>The C<$)> special variable has always (well, in Perl 5, at least)reflected not only the current effective group, but also the group listas returned by the C<getgroups()> C function (if there is one).However, until this release, there has not been a way to call theC<setgroups()> C function from Perl.In Perl 5.004, assigning to C<$)> is exactly symmetrical with examiningit: The first number in its string value is used as the effective gid;if there are any numbers after the first one, they are passed to theC<setgroups()> C function (if there is one).=head2 Fixed parsing of $$<digit>, &$<digit>, etc.Perl versions before 5.004 misinterpreted any type marker followed by"$" and a digit.  For example, "$$0" was incorrectly taken to mean"${$}0" instead of "${$0}".  This bug is (mostly) fixed in Perl 5.004.However, the developers of Perl 5.004 could not fix this bug completely,because at least two widely-used modules depend on the old meaning of"$$0" in a string.  So Perl 5.004 still interprets "$$<digit>" in theold (broken) way inside strings; but it generates this message as awarning.  And in Perl 5.005, this special treatment will cease.=head2 Fixed localization of $<digit>, $&, etc.Perl versions before 5.004 did not always properly localize theregex-related special variables.  Perl 5.004 does localize them, asthe documentation has always said it should.  This may result in $1,$2, etc. no longer being set where existing programs use them.=head2 No resetting of $. on implicit closeThe documentation for Perl 5.0 has always stated that C<$.> is I<not>reset when an already-open file handle is reopened with no interveningcall to C<close>.  Due to a bug, perl versions 5.000 through 5.003I<did> reset C<$.> under that circumstance; Perl 5.004 does not.=head2 C<wantarray> may return undefThe C<wantarray> operator returns true if a subroutine is expected toreturn a list, and false otherwise.  In Perl 5.004, C<wantarray> canalso return the undefined value if a subroutine's return value willnot be used at all, which allows subroutines to avoid a time-consumingcalculation of a return value if it isn't going to be used.=head2 C<eval EXPR> determines value of EXPR in scalar contextPerl (version 5) used to determine the value of EXPR inconsistently,sometimes incorrectly using the surrounding context for the determination.Now, the value of EXPR (before being parsed by eval) is always determined ina scalar context.  Once parsed, it is executed as before, by providingthe context that the scope surrounding the eval provided.  This changemakes the behavior Perl4 compatible, besides fixing bugs resulting fromthe inconsistent behavior.  This program:    @a = qw(time now is time);    print eval @a;    print '|', scalar eval @a;used to print something like "timenowis881399109|4", but now (and in perl4)prints "4|4".=head2 Changes to tainting checksA bug in previous versions may have failed to detect some insecureconditions when taint checks are turned on.  (Taint checks are usedin setuid or setgid scripts, or when explicitly turned on with theC<-T> invocation option.)  Although it's unlikely, this may cause apreviously-working script to now fail -- which should be construedas a blessing, since that indicates a potentially-serious securityhole was just plugged.The new restrictions when tainting include:=over 4=item No glob() or <*>These operators may spawn the C shell (csh), which cannot be madesafe.  This restriction will be lifted in a future version of Perlwhen globbing is implemented without the use of an external program.=item No spawning if tainted $CDPATH, $ENV, $BASH_ENVThese environment variables may alter the behavior of spawned programs(especially shells) in ways that subvert security.  So now they aretreated as dangerous, in the manner of $IFS and $PATH.=item No spawning if tainted $TERM doesn't look like a terminal nameSome termcap libraries do unsafe things with $TERM.  However, it would beunnecessarily harsh to treat all $TERM values as unsafe, since only shellmetacharacters can cause trouble in $TERM.  So a tainted $TERM isconsidered to be safe if it contains only alphanumerics, underscores,dashes, and colons, and unsafe if it contains other characters (includingwhitespace).=back=head2 New Opcode module and revised Safe moduleA new Opcode module supports the creation, manipulation andapplication of opcode masks.  The revised Safe module has a new APIand is implemented using the new Opcode module.  Please read the newOpcode and Safe documentation.=head2 Embedding improvementsIn older versions of Perl it was not possible to create more than onePerl interpreter instance inside a single process without leaking like asieve and/or crashing.  The bugs that caused this behavior have all beenfixed.  However, you still must take care when embedding Perl in a Cprogram.  See the updated perlembed manpage for tips on how to manageyour interpreters.=head2 Internal change: FileHandle class based on IO::* classesFile handles are now stored internally as type IO::Handle.  TheFileHandle module is still supported for backwards compatibility, butit is now merely a front end to the IO::* modules -- specifically,IO::Handle, IO::Seekable, and IO::File.  We suggest, but do notrequire, that you use the IO::* modules in new code.In harmony with this change, C<*GLOB{FILEHANDLE}> is now just abackward-compatible synonym for C<*GLOB{IO}>.=head2 Internal change: PerlIO abstraction interfaceIt is now possible to build Perl with AT&T's sfio IO packageinstead of stdio.  See L<perlapio> for more details, andthe F<INSTALL> file for how to use it.=head2 New and changed syntax=over 4=item $coderef->(PARAMS)A subroutine reference may now be suffixed with an arrow and a(possibly empty) parameter list.  This syntax denotes a call of thereferenced subroutine, with the given parameters (if any).This new syntax follows the pattern of S<C<< $hashref->{FOO} >>> andS<C<< $aryref->[$foo] >>>: You may now write S<C<&$subref($foo)>> asS<C<< $subref->($foo) >>>.  All these arrow terms may be chained;thus, S<C<< &{$table->{FOO}}($bar) >>> may now be writtenS<C<< $table->{FOO}->($bar) >>>.=back=head2 New and changed builtin constants=over 4=item __PACKAGE__The current package name at compile time, or the undefined value ifthere is no current package (due to a C<package;> directive).  LikeC<__FILE__> and C<__LINE__>, C<__PACKAGE__> does I<not> interpolateinto strings.=back=head2 New and changed builtin variables=over 4=item $^EExtended error message on some platforms.  (Also known as$EXTENDED_OS_ERROR if you C<use English>).=item $^HThe current set of syntax checks enabled by C<use strict>.  See thedocumentation of C<strict> for more details.  Not actually new, butnewly documented.Because it is intended for internal use by Perl core components,there is no C<use English> long name for this variable.=item $^MBy default, running out of memory it is not trappable.  However, ifcompiled for this, Perl may use the contents of C<$^M> as an emergencypool after die()ing with this message.  Suppose that your Perl werecompiled with -DPERL_EMERGENCY_SBRK and used Perl's malloc.  Then    $^M = 'a' x (1<<16);would allocate a 64K buffer for use when in emergency.See the F<INSTALL> file for information on how to enable this option.As a disincentive to casual use of this advanced feature,there is no C<use English> long name for this variable.=back=head2 New and changed builtin functions=over 4=item delete on slicesThis now works.  (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)=item flockis now supported on more platforms, prefers fcntl to lockf whenemulating, and always flushes before (un)locking.=item printf and sprintfPerl now implements these functions itself; it doesn't use the Clibrary function sprintf() any more, except for floating-pointnumbers, and even then only known flags are allowed.  As a result, itis now possible to know which conversions and flags will work, andwhat they will do.The new conversions in Perl's sprintf() are:   %i	a synonym for %d   %p	a pointer (the address of the Perl value, in hexadecimal)   %n	special: *stores* the number of characters output so far        into the next variable in the parameter list The new flags that go between the C<%> and the conversion are:   #	prefix octal with "0", hex with "0x"   h	interpret integer as C type "short" or "unsigned short"   V	interpret integer as Perl's standard integer typeAlso, where a number would appear in the flags, an asterisk ("*") maybe used instead, in which case Perl uses the next item in theparameter list as the given number (that is, as the field width orprecision).  If a field width obtained through "*" is negative, it hasthe same effect as the '-' flag: left-justification.See L<perlfunc/sprintf> for a complete list of conversion and flags.=item keys as an lvalueAs an lvalue, C<keys> allows you to increase the number of hash bucketsallocated for the given hash.  This can gain you a measure of efficiency ifyou know the hash is going to get big.  (This is similar to pre-extendingan array by assigning a larger number to $#array.)  If you say    keys %hash = 200;then C<%hash> will have at least 200 buckets allocated for it.  Thesebuckets will be retained even if you do C<%hash = ()>; use C<undef%hash> if you want to free the storage while C<%hash> is still in scope.You can't shrink the number of buckets allocated for the hash usingC<keys> in this way (but you needn't worry about doing this by accident,as trying has no effect).=item my() in Control StructuresYou can now use my() (with or without the parentheses) in the controlexpressions of control structures such as:    while (defined(my $line = <>)) {        $line = lc $line;    } continue {        print $line;    }    if ((my $answer = <STDIN>) =~ /^y(es)?$/i) {        user_agrees();    } elsif ($answer =~ /^n(o)?$/i) {        user_disagrees();    } else {        chomp $answer;        die "`$answer' is neither `yes' nor `no'";    }Also, you can declare a foreach loop control variable as lexical by

⌨️ 快捷键说明

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