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

📄 perl5004delta.pod

📁 MSYS在windows下模拟了一个类unix的终端
💻 POD
📖 第 1 页 / 共 4 页
字号:
preceding it with the word "my".  For example, in:    foreach my $i (1, 2, 3) {        some_function();    }$i is a lexical variable, and the scope of $i extends to the end ofthe loop, but not beyond it.Note that you still cannot use my() on global punctuation variablessuch as $_ and the like.=item pack() and unpack()A new format 'w' represents a BER compressed integer (as defined inASN.1).  Its format is a sequence of one or more bytes, each of whichprovides seven bits of the total value, with the most significantfirst.  Bit eight of each byte is set, except for the last byte, inwhich bit eight is clear.If 'p' or 'P' are given undef as values, they now generate a NULLpointer.Both pack() and unpack() now fail when their templates contain invalidtypes.  (Invalid types used to be ignored.)=item sysseek()The new sysseek() operator is a variant of seek() that sets and gets thefile's system read/write position, using the lseek(2) system call.  It isthe only reliable way to seek before using sysread() or syswrite().  Itsreturn value is the new position, or the undefined value on failure.=item use VERSIONIf the first argument to C<use> is a number, it is treated as a versionnumber instead of a module name.  If the version of the Perl interpreteris less than VERSION, then an error message is printed and Perl exitsimmediately.  Because C<use> occurs at compile time, this check happensimmediately during the compilation process, unlike C<require VERSION>,which waits until runtime for the check.  This is often useful if youneed to check the current Perl version before C<use>ing library moduleswhich have changed in incompatible ways from older versions of Perl.(We try not to do this more than we have to.)=item use Module VERSION LISTIf the VERSION argument is present between Module and LIST, then theC<use> will call the VERSION method in class Module with the givenversion as an argument.  The default VERSION method, inherited fromthe UNIVERSAL class, croaks if the given version is larger than thevalue of the variable $Module::VERSION.  (Note that there is not acomma after VERSION!)This version-checking mechanism is similar to the one currently usedin the Exporter module, but it is faster and can be used with modulesthat don't use the Exporter.  It is the recommended method for newcode.=item prototype(FUNCTION)Returns the prototype of a function as a string (or C<undef> if thefunction has no prototype).  FUNCTION is a reference to or the name of thefunction whose prototype you want to retrieve.(Not actually new; just never documented before.)=item srandThe default seed for C<srand>, which used to be C<time>, has been changed.Now it's a heady mix of difficult-to-predict system-dependent values,which should be sufficient for most everyday purposes.Previous to version 5.004, calling C<rand> without first calling C<srand>would yield the same sequence of random numbers on most or all machines.Now, when perl sees that you're calling C<rand> and haven't yet calledC<srand>, it calls C<srand> with the default seed. You should still callC<srand> manually if your code might ever be run on a pre-5.004 system,of course, or if you want a seed other than the default.=item $_ as DefaultFunctions documented in the Camel to default to $_ now infact do, and all those that do are so documented in L<perlfunc>.=item C<m//gc> does not reset search position on failureThe C<m//g> match iteration construct has always reset its targetstring's search position (which is visible through the C<pos> operator)when a match fails; as a result, the next C<m//g> match after a failurestarts again at the beginning of the string.  With Perl 5.004, thisreset may be disabled by adding the "c" (for "continue") modifier,i.e. C<m//gc>.  This feature, in conjunction with the C<\G> zero-widthassertion, makes it possible to chain matches together.  See L<perlop>and L<perlre>.=item C<m//x> ignores whitespace before ?*+{}The C<m//x> construct has always been intended to ignore all unescapedwhitespace.  However, before Perl 5.004, whitespace had the effect ofescaping repeat modifiers like "*" or "?"; for example, C</a *b/x> was(mis)interpreted as C</a\*b/x>.  This bug has been fixed in 5.004.=item nested C<sub{}> closures work nowPrior to the 5.004 release, nested anonymous functions didn't workright.  They do now.=item formats work right on changing lexicalsJust like anonymous functions that contain lexical variablesthat change (like a lexical index variable for a C<foreach> loop),formats now work properly.  For example, this silently failedbefore (printed only zeros), but is fine now:    my $i;    foreach $i ( 1 .. 10 ) {	write;    }    format =	my i is @#	$i    .However, it still fails (without a warning) if the foreach is within asubroutine:    my $i;    sub foo {      foreach $i ( 1 .. 10 ) {	write;      }    }    foo;    format =	my i is @#	$i    .=back=head2 New builtin methodsThe C<UNIVERSAL> package automatically contains the following methods thatare inherited by all other classes:=over 4=item isa(CLASS)C<isa> returns I<true> if its object is blessed into a subclass of C<CLASS>C<isa> is also exportable and can be called as a sub with two arguments. Thisallows the ability to check what a reference points to. Example:    use UNIVERSAL qw(isa);    if(isa($ref, 'ARRAY')) {       ...    }=item can(METHOD)C<can> checks to see if its object has a method called C<METHOD>,if it does then a reference to the sub is returned; if it does not thenI<undef> is returned.=item VERSION( [NEED] )C<VERSION> returns the version number of the class (package).  If theNEED argument is given then it will check that the current version (asdefined by the $VERSION variable in the given package) not less thanNEED; it will die if this is not the case.  This method is normallycalled as a class method.  This method is called automatically by theC<VERSION> form of C<use>.    use A 1.2 qw(some imported subs);    # implies:    A->VERSION(1.2);=backB<NOTE:> C<can> directly uses Perl's internal code for method lookup, andC<isa> uses a very similar method and caching strategy. This may causestrange effects if the Perl code dynamically changes @ISA in any package.You may add other methods to the UNIVERSAL class via Perl or XS code.You do not need to C<use UNIVERSAL> in order to make these methodsavailable to your program.  This is necessary only if you wish tohave C<isa> available as a plain subroutine in the current package.=head2 TIEHANDLE now supportedSee L<perltie> for other kinds of tie()s.=over 4=item TIEHANDLE classname, LISTThis is the constructor for the class.  That means it is expected toreturn an object of some sort. The reference can be used tohold some internal information.    sub TIEHANDLE {	print "<shout>\n";	my $i;	return bless \$i, shift;    }=item PRINT this, LISTThis method will be triggered every time the tied handle is printed to.Beyond its self reference it also expects the list that was passed tothe print function.    sub PRINT {	$r = shift;	$$r++;	return print join( $, => map {uc} @_), $\;    }=item PRINTF this, LISTThis method will be triggered every time the tied handle is printed towith the C<printf()> function.Beyond its self reference it also expects the format and list that waspassed to the printf function.    sub PRINTF {        shift;	  my $fmt = shift;        print sprintf($fmt, @_)."\n";    }=item READ this LISTThis method will be called when the handle is read from via the C<read>or C<sysread> functions.    sub READ {	$r = shift;	my($buf,$len,$offset) = @_;	print "READ called, \$buf=$buf, \$len=$len, \$offset=$offset";    }=item READLINE thisThis method will be called when the handle is read from. The methodshould return undef when there is no more data.    sub READLINE {	$r = shift;	return "PRINT called $$r times\n"    }=item GETC thisThis method will be called when the C<getc> function is called.    sub GETC { print "Don't GETC, Get Perl"; return "a"; }=item DESTROY thisAs with the other types of ties, this method will be called when thetied handle is about to be destroyed. This is useful for debugging andpossibly for cleaning up.    sub DESTROY {	print "</shout>\n";    }=back=head2 Malloc enhancementsIf perl is compiled with the malloc included with the perl distribution(that is, if C<perl -V:d_mymalloc> is 'define') then you can printmemory statistics at runtime by running Perl thusly:  env PERL_DEBUG_MSTATS=2 perl your_script_hereThe value of 2 means to print statistics after compilation and onexit; with a value of 1, the statistics are printed only on exit.(If you want the statistics at an arbitrary time, you'll need toinstall the optional module Devel::Peek.)Three new compilation flags are recognized by malloc.c.  (They have noeffect if perl is compiled with system malloc().)=over 4=item -DPERL_EMERGENCY_SBRKIf this macro is defined, running out of memory need not be a fatalerror: a memory pool can allocated by assigning to the specialvariable C<$^M>.  See L<"$^M">.=item -DPACK_MALLOCPerl memory allocation is by bucket with sizes close to powers of two.Because of these malloc overhead may be big, especially for data ofsize exactly a power of two.  If C<PACK_MALLOC> is defined, perl usesa slightly different algorithm for small allocations (up to 64 byteslong), which makes it possible to have overhead down to 1 byte forallocations which are powers of two (and appear quite often).Expected memory savings (with 8-byte alignment in C<alignbytes>) isabout 20% for typical Perl usage.  Expected slowdown due to additionalmalloc overhead is in fractions of a percent (hard to measure, becauseof the effect of saved memory on speed).=item -DTWO_POT_OPTIMIZESimilarly to C<PACK_MALLOC>, this macro improves allocations of datawith size close to a power of two; but this works for big allocations(starting with 16K by default).  Such allocations are typical for bighashes and special-purpose scripts, especially image processing.On recent systems, the fact that perl requires 2M from system for 1Mallocation will not affect speed of execution, since the tail of sucha chunk is not going to be touched (and thus will not require realmemory).  However, it may result in a premature out-of-memory error.So if you will be manipulating very large blocks with sizes close topowers of two, it would be wise to define this macro.Expected saving of memory is 0-100% (100% in applications whichrequire most memory in such 2**n chunks); expected slowdown isnegligible.=back=head2 Miscellaneous efficiency enhancementsFunctions that have an empty prototype and that do nothing but returna fixed value are now inlined (e.g. C<sub PI () { 3.14159 }>).Each unique hash key is only allocated once, no matter how many hasheshave an entry with that key.  So even if you have 100 copies of thesame hash, the hash keys never have to be reallocated.=head1 Support for More Operating SystemsSupport for the following operating systems is new in Perl 5.004.=head2 Win32Perl 5.004 now includes support for building a "native" perl underWindows NT, using the Microsoft Visual C++ compiler (versions 2.0and above) or the Borland C++ compiler (versions 5.02 and above).The resulting perl can be used under Windows 95 (if itis installed in the same directory locations as it got installedin Windows NT).  This port includes support for perl extensionbuilding tools like L<MakeMaker> and L<h2xs>, so that many extensionsavailable on the Comprehensive Perl Archive Network (CPAN) can now bereadily built under Windows NT.  See http://www.perl.com/ for moreinformation on CPAN and F<README.win32> in the perl distribution for moredetails on how to get started with building this port.There is also support for building perl under the Cygwin32 environment.Cygwin32 is a set of GNU tools that make it possible to compile and runmany Unix programs under Windows NT by providing a mostly Unix-like interface for compilation and execution.  See F<README.cygwin32> in theperl distribution for more details on this port and how to obtain theCygwin32 toolkit.=head2 Plan 9See F<README.plan9> in the perl distribution.=head2 QNXSee F<README.qnx> in the perl distribution.=head2 AmigaOSSee F<README.amigaos> in the perl distribution.=head1 PragmataSix new pragmatic modules exist:=over 4=item use autouse MODULE => qw(sub1 sub2 sub3)Defers C<require MODULE> until someone calls one of the specifiedsubroutines (which must be exported by MODULE).  This pragma should beused with caution, and only when necessary.=item use blib=item use blib 'dir'Looks for MakeMaker-like I<'blib'> directory structure starting inI<dir> (or current directory) and working back up to five levels ofparent directories.Intended for use on command line with B<-M> option as a way of testingarbitrary scripts against an uninstalled version of a package.=item use constant NAME => VALUEProvides a convenient interface for creating compile-time constants,See L<perlsub/"Constant Functions">.

⌨️ 快捷键说明

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