| 1 | =head1 NAME
|
|---|
| 2 |
|
|---|
| 3 | perl56delta - what's new for perl v5.6.0
|
|---|
| 4 |
|
|---|
| 5 | =head1 DESCRIPTION
|
|---|
| 6 |
|
|---|
| 7 | This document describes differences between the 5.005 release and the 5.6.0
|
|---|
| 8 | release.
|
|---|
| 9 |
|
|---|
| 10 | =head1 Core Enhancements
|
|---|
| 11 |
|
|---|
| 12 | =head2 Interpreter cloning, threads, and concurrency
|
|---|
| 13 |
|
|---|
| 14 | Perl 5.6.0 introduces the beginnings of support for running multiple
|
|---|
| 15 | interpreters concurrently in different threads. In conjunction with
|
|---|
| 16 | the perl_clone() API call, which can be used to selectively duplicate
|
|---|
| 17 | the state of any given interpreter, it is possible to compile a
|
|---|
| 18 | piece of code once in an interpreter, clone that interpreter
|
|---|
| 19 | one or more times, and run all the resulting interpreters in distinct
|
|---|
| 20 | threads.
|
|---|
| 21 |
|
|---|
| 22 | On the Windows platform, this feature is used to emulate fork() at the
|
|---|
| 23 | interpreter level. See L<perlfork> for details about that.
|
|---|
| 24 |
|
|---|
| 25 | This feature is still in evolution. It is eventually meant to be used
|
|---|
| 26 | to selectively clone a subroutine and data reachable from that
|
|---|
| 27 | subroutine in a separate interpreter and run the cloned subroutine
|
|---|
| 28 | in a separate thread. Since there is no shared data between the
|
|---|
| 29 | interpreters, little or no locking will be needed (unless parts of
|
|---|
| 30 | the symbol table are explicitly shared). This is obviously intended
|
|---|
| 31 | to be an easy-to-use replacement for the existing threads support.
|
|---|
| 32 |
|
|---|
| 33 | Support for cloning interpreters and interpreter concurrency can be
|
|---|
| 34 | enabled using the -Dusethreads Configure option (see win32/Makefile for
|
|---|
| 35 | how to enable it on Windows.) The resulting perl executable will be
|
|---|
| 36 | functionally identical to one that was built with -Dmultiplicity, but
|
|---|
| 37 | the perl_clone() API call will only be available in the former.
|
|---|
| 38 |
|
|---|
| 39 | -Dusethreads enables the cpp macro USE_ITHREADS by default, which in turn
|
|---|
| 40 | enables Perl source code changes that provide a clear separation between
|
|---|
| 41 | the op tree and the data it operates with. The former is immutable, and
|
|---|
| 42 | can therefore be shared between an interpreter and all of its clones,
|
|---|
| 43 | while the latter is considered local to each interpreter, and is therefore
|
|---|
| 44 | copied for each clone.
|
|---|
| 45 |
|
|---|
| 46 | Note that building Perl with the -Dusemultiplicity Configure option
|
|---|
| 47 | is adequate if you wish to run multiple B<independent> interpreters
|
|---|
| 48 | concurrently in different threads. -Dusethreads only provides the
|
|---|
| 49 | additional functionality of the perl_clone() API call and other
|
|---|
| 50 | support for running B<cloned> interpreters concurrently.
|
|---|
| 51 |
|
|---|
| 52 | NOTE: This is an experimental feature. Implementation details are
|
|---|
| 53 | subject to change.
|
|---|
| 54 |
|
|---|
| 55 | =head2 Lexically scoped warning categories
|
|---|
| 56 |
|
|---|
| 57 | You can now control the granularity of warnings emitted by perl at a finer
|
|---|
| 58 | level using the C<use warnings> pragma. L<warnings> and L<perllexwarn>
|
|---|
| 59 | have copious documentation on this feature.
|
|---|
| 60 |
|
|---|
| 61 | =head2 Unicode and UTF-8 support
|
|---|
| 62 |
|
|---|
| 63 | Perl now uses UTF-8 as its internal representation for character
|
|---|
| 64 | strings. The C<utf8> and C<bytes> pragmas are used to control this support
|
|---|
| 65 | in the current lexical scope. See L<perlunicode>, L<utf8> and L<bytes> for
|
|---|
| 66 | more information.
|
|---|
| 67 |
|
|---|
| 68 | This feature is expected to evolve quickly to support some form of I/O
|
|---|
| 69 | disciplines that can be used to specify the kind of input and output data
|
|---|
| 70 | (bytes or characters). Until that happens, additional modules from CPAN
|
|---|
| 71 | will be needed to complete the toolkit for dealing with Unicode.
|
|---|
| 72 |
|
|---|
| 73 | NOTE: This should be considered an experimental feature. Implementation
|
|---|
| 74 | details are subject to change.
|
|---|
| 75 |
|
|---|
| 76 | =head2 Support for interpolating named characters
|
|---|
| 77 |
|
|---|
| 78 | The new C<\N> escape interpolates named characters within strings.
|
|---|
| 79 | For example, C<"Hi! \N{WHITE SMILING FACE}"> evaluates to a string
|
|---|
| 80 | with a unicode smiley face at the end.
|
|---|
| 81 |
|
|---|
| 82 | =head2 "our" declarations
|
|---|
| 83 |
|
|---|
| 84 | An "our" declaration introduces a value that can be best understood
|
|---|
| 85 | as a lexically scoped symbolic alias to a global variable in the
|
|---|
| 86 | package that was current where the variable was declared. This is
|
|---|
| 87 | mostly useful as an alternative to the C<vars> pragma, but also provides
|
|---|
| 88 | the opportunity to introduce typing and other attributes for such
|
|---|
| 89 | variables. See L<perlfunc/our>.
|
|---|
| 90 |
|
|---|
| 91 | =head2 Support for strings represented as a vector of ordinals
|
|---|
| 92 |
|
|---|
| 93 | Literals of the form C<v1.2.3.4> are now parsed as a string composed
|
|---|
| 94 | of characters with the specified ordinals. This is an alternative, more
|
|---|
| 95 | readable way to construct (possibly unicode) strings instead of
|
|---|
| 96 | interpolating characters, as in C<"\x{1}\x{2}\x{3}\x{4}">. The leading
|
|---|
| 97 | C<v> may be omitted if there are more than two ordinals, so C<1.2.3> is
|
|---|
| 98 | parsed the same as C<v1.2.3>.
|
|---|
| 99 |
|
|---|
| 100 | Strings written in this form are also useful to represent version "numbers".
|
|---|
| 101 | It is easy to compare such version "numbers" (which are really just plain
|
|---|
| 102 | strings) using any of the usual string comparison operators C<eq>, C<ne>,
|
|---|
| 103 | C<lt>, C<gt>, etc., or perform bitwise string operations on them using C<|>,
|
|---|
| 104 | C<&>, etc.
|
|---|
| 105 |
|
|---|
| 106 | In conjunction with the new C<$^V> magic variable (which contains
|
|---|
| 107 | the perl version as a string), such literals can be used as a readable way
|
|---|
| 108 | to check if you're running a particular version of Perl:
|
|---|
| 109 |
|
|---|
| 110 | # this will parse in older versions of Perl also
|
|---|
| 111 | if ($^V and $^V gt v5.6.0) {
|
|---|
| 112 | # new features supported
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | C<require> and C<use> also have some special magic to support such
|
|---|
| 116 | literals, but this particular usage should be avoided because it leads to
|
|---|
| 117 | misleading error messages under versions of Perl which don't support vector
|
|---|
| 118 | strings. Using a true version number will ensure correct behavior in all
|
|---|
| 119 | versions of Perl:
|
|---|
| 120 |
|
|---|
| 121 | require 5.006; # run time check for v5.6
|
|---|
| 122 | use 5.006_001; # compile time check for v5.6.1
|
|---|
| 123 |
|
|---|
| 124 | Also, C<sprintf> and C<printf> support the Perl-specific format flag C<%v>
|
|---|
| 125 | to print ordinals of characters in arbitrary strings:
|
|---|
| 126 |
|
|---|
| 127 | printf "v%vd", $^V; # prints current version, such as "v5.5.650"
|
|---|
| 128 | printf "%*vX", ":", $addr; # formats IPv6 address
|
|---|
| 129 | printf "%*vb", " ", $bits; # displays bitstring
|
|---|
| 130 |
|
|---|
| 131 | See L<perldata/"Scalar value constructors"> for additional information.
|
|---|
| 132 |
|
|---|
| 133 | =head2 Improved Perl version numbering system
|
|---|
| 134 |
|
|---|
| 135 | Beginning with Perl version 5.6.0, the version number convention has been
|
|---|
| 136 | changed to a "dotted integer" scheme that is more commonly found in open
|
|---|
| 137 | source projects.
|
|---|
| 138 |
|
|---|
| 139 | Maintenance versions of v5.6.0 will be released as v5.6.1, v5.6.2 etc.
|
|---|
| 140 | The next development series following v5.6.0 will be numbered v5.7.x,
|
|---|
| 141 | beginning with v5.7.0, and the next major production release following
|
|---|
| 142 | v5.6.0 will be v5.8.0.
|
|---|
| 143 |
|
|---|
| 144 | The English module now sets $PERL_VERSION to $^V (a string value) rather
|
|---|
| 145 | than C<$]> (a numeric value). (This is a potential incompatibility.
|
|---|
| 146 | Send us a report via perlbug if you are affected by this.)
|
|---|
| 147 |
|
|---|
| 148 | The v1.2.3 syntax is also now legal in Perl.
|
|---|
| 149 | See L<Support for strings represented as a vector of ordinals> for more on that.
|
|---|
| 150 |
|
|---|
| 151 | To cope with the new versioning system's use of at least three significant
|
|---|
| 152 | digits for each version component, the method used for incrementing the
|
|---|
| 153 | subversion number has also changed slightly. We assume that versions older
|
|---|
| 154 | than v5.6.0 have been incrementing the subversion component in multiples of
|
|---|
| 155 | 10. Versions after v5.6.0 will increment them by 1. Thus, using the new
|
|---|
| 156 | notation, 5.005_03 is the "same" as v5.5.30, and the first maintenance
|
|---|
| 157 | version following v5.6.0 will be v5.6.1 (which should be read as being
|
|---|
| 158 | equivalent to a floating point value of 5.006_001 in the older format,
|
|---|
| 159 | stored in C<$]>).
|
|---|
| 160 |
|
|---|
| 161 | =head2 New syntax for declaring subroutine attributes
|
|---|
| 162 |
|
|---|
| 163 | Formerly, if you wanted to mark a subroutine as being a method call or
|
|---|
| 164 | as requiring an automatic lock() when it is entered, you had to declare
|
|---|
| 165 | that with a C<use attrs> pragma in the body of the subroutine.
|
|---|
| 166 | That can now be accomplished with declaration syntax, like this:
|
|---|
| 167 |
|
|---|
| 168 | sub mymethod : locked method;
|
|---|
| 169 | ...
|
|---|
| 170 | sub mymethod : locked method {
|
|---|
| 171 | ...
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | sub othermethod :locked :method;
|
|---|
| 175 | ...
|
|---|
| 176 | sub othermethod :locked :method {
|
|---|
| 177 | ...
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 | (Note how only the first C<:> is mandatory, and whitespace surrounding
|
|---|
| 182 | the C<:> is optional.)
|
|---|
| 183 |
|
|---|
| 184 | F<AutoSplit.pm> and F<SelfLoader.pm> have been updated to keep the attributes
|
|---|
| 185 | with the stubs they provide. See L<attributes>.
|
|---|
| 186 |
|
|---|
| 187 | =head2 File and directory handles can be autovivified
|
|---|
| 188 |
|
|---|
| 189 | Similar to how constructs such as C<< $x->[0] >> autovivify a reference,
|
|---|
| 190 | handle constructors (open(), opendir(), pipe(), socketpair(), sysopen(),
|
|---|
| 191 | socket(), and accept()) now autovivify a file or directory handle
|
|---|
| 192 | if the handle passed to them is an uninitialized scalar variable. This
|
|---|
| 193 | allows the constructs such as C<open(my $fh, ...)> and C<open(local $fh,...)>
|
|---|
| 194 | to be used to create filehandles that will conveniently be closed
|
|---|
| 195 | automatically when the scope ends, provided there are no other references
|
|---|
| 196 | to them. This largely eliminates the need for typeglobs when opening
|
|---|
| 197 | filehandles that must be passed around, as in the following example:
|
|---|
| 198 |
|
|---|
| 199 | sub myopen {
|
|---|
| 200 | open my $fh, "@_"
|
|---|
| 201 | or die "Can't open '@_': $!";
|
|---|
| 202 | return $fh;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | {
|
|---|
| 206 | my $f = myopen("</etc/motd");
|
|---|
| 207 | print <$f>;
|
|---|
| 208 | # $f implicitly closed here
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | =head2 open() with more than two arguments
|
|---|
| 212 |
|
|---|
| 213 | If open() is passed three arguments instead of two, the second argument
|
|---|
| 214 | is used as the mode and the third argument is taken to be the file name.
|
|---|
| 215 | This is primarily useful for protecting against unintended magic behavior
|
|---|
| 216 | of the traditional two-argument form. See L<perlfunc/open>.
|
|---|
| 217 |
|
|---|
| 218 | =head2 64-bit support
|
|---|
| 219 |
|
|---|
| 220 | Any platform that has 64-bit integers either
|
|---|
| 221 |
|
|---|
| 222 | (1) natively as longs or ints
|
|---|
| 223 | (2) via special compiler flags
|
|---|
| 224 | (3) using long long or int64_t
|
|---|
| 225 |
|
|---|
| 226 | is able to use "quads" (64-bit integers) as follows:
|
|---|
| 227 |
|
|---|
| 228 | =over 4
|
|---|
| 229 |
|
|---|
| 230 | =item *
|
|---|
| 231 |
|
|---|
| 232 | constants (decimal, hexadecimal, octal, binary) in the code
|
|---|
| 233 |
|
|---|
| 234 | =item *
|
|---|
| 235 |
|
|---|
| 236 | arguments to oct() and hex()
|
|---|
| 237 |
|
|---|
| 238 | =item *
|
|---|
| 239 |
|
|---|
| 240 | arguments to print(), printf() and sprintf() (flag prefixes ll, L, q)
|
|---|
| 241 |
|
|---|
| 242 | =item *
|
|---|
| 243 |
|
|---|
| 244 | printed as such
|
|---|
| 245 |
|
|---|
| 246 | =item *
|
|---|
| 247 |
|
|---|
| 248 | pack() and unpack() "q" and "Q" formats
|
|---|
| 249 |
|
|---|
| 250 | =item *
|
|---|
| 251 |
|
|---|
| 252 | in basic arithmetics: + - * / % (NOTE: operating close to the limits
|
|---|
| 253 | of the integer values may produce surprising results)
|
|---|
| 254 |
|
|---|
| 255 | =item *
|
|---|
| 256 |
|
|---|
| 257 | in bit arithmetics: & | ^ ~ << >> (NOTE: these used to be forced
|
|---|
| 258 | to be 32 bits wide but now operate on the full native width.)
|
|---|
| 259 |
|
|---|
| 260 | =item *
|
|---|
| 261 |
|
|---|
| 262 | vec()
|
|---|
| 263 |
|
|---|
| 264 | =back
|
|---|
| 265 |
|
|---|
| 266 | Note that unless you have the case (a) you will have to configure
|
|---|
| 267 | and compile Perl using the -Duse64bitint Configure flag.
|
|---|
| 268 |
|
|---|
| 269 | NOTE: The Configure flags -Duselonglong and -Duse64bits have been
|
|---|
| 270 | deprecated. Use -Duse64bitint instead.
|
|---|
| 271 |
|
|---|
| 272 | There are actually two modes of 64-bitness: the first one is achieved
|
|---|
| 273 | using Configure -Duse64bitint and the second one using Configure
|
|---|
| 274 | -Duse64bitall. The difference is that the first one is minimal and
|
|---|
| 275 | the second one maximal. The first works in more places than the second.
|
|---|
| 276 |
|
|---|
| 277 | The C<use64bitint> does only as much as is required to get 64-bit
|
|---|
| 278 | integers into Perl (this may mean, for example, using "long longs")
|
|---|
| 279 | while your memory may still be limited to 2 gigabytes (because your
|
|---|
| 280 | pointers could still be 32-bit). Note that the name C<64bitint> does
|
|---|
| 281 | not imply that your C compiler will be using 64-bit C<int>s (it might,
|
|---|
| 282 | but it doesn't have to): the C<use64bitint> means that you will be
|
|---|
| 283 | able to have 64 bits wide scalar values.
|
|---|
| 284 |
|
|---|
| 285 | The C<use64bitall> goes all the way by attempting to switch also
|
|---|
| 286 | integers (if it can), longs (and pointers) to being 64-bit. This may
|
|---|
| 287 | create an even more binary incompatible Perl than -Duse64bitint: the
|
|---|
| 288 | resulting executable may not run at all in a 32-bit box, or you may
|
|---|
| 289 | have to reboot/reconfigure/rebuild your operating system to be 64-bit
|
|---|
| 290 | aware.
|
|---|
| 291 |
|
|---|
| 292 | Natively 64-bit systems like Alpha and Cray need neither -Duse64bitint
|
|---|
| 293 | nor -Duse64bitall.
|
|---|
| 294 |
|
|---|
| 295 | Last but not least: note that due to Perl's habit of always using
|
|---|
| 296 | floating point numbers, the quads are still not true integers.
|
|---|
| 297 | When quads overflow their limits (0...18_446_744_073_709_551_615 unsigned,
|
|---|
| 298 | -9_223_372_036_854_775_808...9_223_372_036_854_775_807 signed), they
|
|---|
| 299 | are silently promoted to floating point numbers, after which they will
|
|---|
| 300 | start losing precision (in their lower digits).
|
|---|
| 301 |
|
|---|
| 302 | NOTE: 64-bit support is still experimental on most platforms.
|
|---|
| 303 | Existing support only covers the LP64 data model. In particular, the
|
|---|
| 304 | LLP64 data model is not yet supported. 64-bit libraries and system
|
|---|
| 305 | APIs on many platforms have not stabilized--your mileage may vary.
|
|---|
| 306 |
|
|---|
| 307 | =head2 Large file support
|
|---|
| 308 |
|
|---|
| 309 | If you have filesystems that support "large files" (files larger than
|
|---|
| 310 | 2 gigabytes), you may now also be able to create and access them from
|
|---|
| 311 | Perl.
|
|---|
| 312 |
|
|---|
| 313 | NOTE: The default action is to enable large file support, if
|
|---|
| 314 | available on the platform.
|
|---|
| 315 |
|
|---|
| 316 | If the large file support is on, and you have a Fcntl constant
|
|---|
| 317 | O_LARGEFILE, the O_LARGEFILE is automatically added to the flags
|
|---|
| 318 | of sysopen().
|
|---|
| 319 |
|
|---|
| 320 | Beware that unless your filesystem also supports "sparse files" seeking
|
|---|
| 321 | to umpteen petabytes may be inadvisable.
|
|---|
| 322 |
|
|---|
| 323 | Note that in addition to requiring a proper file system to do large
|
|---|
| 324 | files you may also need to adjust your per-process (or your
|
|---|
| 325 | per-system, or per-process-group, or per-user-group) maximum filesize
|
|---|
| 326 | limits before running Perl scripts that try to handle large files,
|
|---|
| 327 | especially if you intend to write such files.
|
|---|
| 328 |
|
|---|
| 329 | Finally, in addition to your process/process group maximum filesize
|
|---|
| 330 | limits, you may have quota limits on your filesystems that stop you
|
|---|
| 331 | (your user id or your user group id) from using large files.
|
|---|
| 332 |
|
|---|
| 333 | Adjusting your process/user/group/file system/operating system limits
|
|---|
| 334 | is outside the scope of Perl core language. For process limits, you
|
|---|
| 335 | may try increasing the limits using your shell's limits/limit/ulimit
|
|---|
| 336 | command before running Perl. The BSD::Resource extension (not
|
|---|
| 337 | included with the standard Perl distribution) may also be of use, it
|
|---|
| 338 | offers the getrlimit/setrlimit interface that can be used to adjust
|
|---|
| 339 | process resource usage limits, including the maximum filesize limit.
|
|---|
| 340 |
|
|---|
| 341 | =head2 Long doubles
|
|---|
| 342 |
|
|---|
| 343 | In some systems you may be able to use long doubles to enhance the
|
|---|
| 344 | range and precision of your double precision floating point numbers
|
|---|
| 345 | (that is, Perl's numbers). Use Configure -Duselongdouble to enable
|
|---|
| 346 | this support (if it is available).
|
|---|
| 347 |
|
|---|
| 348 | =head2 "more bits"
|
|---|
| 349 |
|
|---|
| 350 | You can "Configure -Dusemorebits" to turn on both the 64-bit support
|
|---|
| 351 | and the long double support.
|
|---|
| 352 |
|
|---|
| 353 | =head2 Enhanced support for sort() subroutines
|
|---|
| 354 |
|
|---|
| 355 | Perl subroutines with a prototype of C<($$)>, and XSUBs in general, can
|
|---|
| 356 | now be used as sort subroutines. In either case, the two elements to
|
|---|
| 357 | be compared are passed as normal parameters in @_. See L<perlfunc/sort>.
|
|---|
| 358 |
|
|---|
| 359 | For unprototyped sort subroutines, the historical behavior of passing
|
|---|
| 360 | the elements to be compared as the global variables $a and $b remains
|
|---|
| 361 | unchanged.
|
|---|
| 362 |
|
|---|
| 363 | =head2 C<sort $coderef @foo> allowed
|
|---|
| 364 |
|
|---|
| 365 | sort() did not accept a subroutine reference as the comparison
|
|---|
| 366 | function in earlier versions. This is now permitted.
|
|---|
| 367 |
|
|---|
| 368 | =head2 File globbing implemented internally
|
|---|
| 369 |
|
|---|
| 370 | Perl now uses the File::Glob implementation of the glob() operator
|
|---|
| 371 | automatically. This avoids using an external csh process and the
|
|---|
| 372 | problems associated with it.
|
|---|
| 373 |
|
|---|
| 374 | NOTE: This is currently an experimental feature. Interfaces and
|
|---|
| 375 | implementation are subject to change.
|
|---|
| 376 |
|
|---|
| 377 | =head2 Support for CHECK blocks
|
|---|
| 378 |
|
|---|
| 379 | In addition to C<BEGIN>, C<INIT>, C<END>, C<DESTROY> and C<AUTOLOAD>,
|
|---|
| 380 | subroutines named C<CHECK> are now special. These are queued up during
|
|---|
| 381 | compilation and behave similar to END blocks, except they are called at
|
|---|
| 382 | the end of compilation rather than at the end of execution. They cannot
|
|---|
| 383 | be called directly.
|
|---|
| 384 |
|
|---|
| 385 | =head2 POSIX character class syntax [: :] supported
|
|---|
| 386 |
|
|---|
| 387 | For example to match alphabetic characters use /[[:alpha:]]/.
|
|---|
| 388 | See L<perlre> for details.
|
|---|
| 389 |
|
|---|
| 390 | =head2 Better pseudo-random number generator
|
|---|
| 391 |
|
|---|
| 392 | In 5.005_0x and earlier, perl's rand() function used the C library
|
|---|
| 393 | rand(3) function. As of 5.005_52, Configure tests for drand48(),
|
|---|
| 394 | random(), and rand() (in that order) and picks the first one it finds.
|
|---|
| 395 |
|
|---|
| 396 | These changes should result in better random numbers from rand().
|
|---|
| 397 |
|
|---|
| 398 | =head2 Improved C<qw//> operator
|
|---|
| 399 |
|
|---|
| 400 | The C<qw//> operator is now evaluated at compile time into a true list
|
|---|
| 401 | instead of being replaced with a run time call to C<split()>. This
|
|---|
| 402 | removes the confusing misbehaviour of C<qw//> in scalar context, which
|
|---|
| 403 | had inherited that behaviour from split().
|
|---|
| 404 |
|
|---|
| 405 | Thus:
|
|---|
| 406 |
|
|---|
| 407 | $foo = ($bar) = qw(a b c); print "$foo|$bar\n";
|
|---|
| 408 |
|
|---|
| 409 | now correctly prints "3|a", instead of "2|a".
|
|---|
| 410 |
|
|---|
| 411 | =head2 Better worst-case behavior of hashes
|
|---|
| 412 |
|
|---|
| 413 | Small changes in the hashing algorithm have been implemented in
|
|---|
| 414 | order to improve the distribution of lower order bits in the
|
|---|
| 415 | hashed value. This is expected to yield better performance on
|
|---|
| 416 | keys that are repeated sequences.
|
|---|
| 417 |
|
|---|
| 418 | =head2 pack() format 'Z' supported
|
|---|
| 419 |
|
|---|
| 420 | The new format type 'Z' is useful for packing and unpacking null-terminated
|
|---|
| 421 | strings. See L<perlfunc/"pack">.
|
|---|
| 422 |
|
|---|
| 423 | =head2 pack() format modifier '!' supported
|
|---|
| 424 |
|
|---|
| 425 | The new format type modifier '!' is useful for packing and unpacking
|
|---|
| 426 | native shorts, ints, and longs. See L<perlfunc/"pack">.
|
|---|
| 427 |
|
|---|
| 428 | =head2 pack() and unpack() support counted strings
|
|---|
| 429 |
|
|---|
| 430 | The template character '/' can be used to specify a counted string
|
|---|
| 431 | type to be packed or unpacked. See L<perlfunc/"pack">.
|
|---|
| 432 |
|
|---|
| 433 | =head2 Comments in pack() templates
|
|---|
| 434 |
|
|---|
| 435 | The '#' character in a template introduces a comment up to
|
|---|
| 436 | end of the line. This facilitates documentation of pack()
|
|---|
| 437 | templates.
|
|---|
| 438 |
|
|---|
| 439 | =head2 Weak references
|
|---|
| 440 |
|
|---|
| 441 | In previous versions of Perl, you couldn't cache objects so as
|
|---|
| 442 | to allow them to be deleted if the last reference from outside
|
|---|
| 443 | the cache is deleted. The reference in the cache would hold a
|
|---|
| 444 | reference count on the object and the objects would never be
|
|---|
| 445 | destroyed.
|
|---|
| 446 |
|
|---|
| 447 | Another familiar problem is with circular references. When an
|
|---|
| 448 | object references itself, its reference count would never go
|
|---|
| 449 | down to zero, and it would not get destroyed until the program
|
|---|
| 450 | is about to exit.
|
|---|
| 451 |
|
|---|
| 452 | Weak references solve this by allowing you to "weaken" any
|
|---|
| 453 | reference, that is, make it not count towards the reference count.
|
|---|
| 454 | When the last non-weak reference to an object is deleted, the object
|
|---|
| 455 | is destroyed and all the weak references to the object are
|
|---|
| 456 | automatically undef-ed.
|
|---|
| 457 |
|
|---|
| 458 | To use this feature, you need the Devel::WeakRef package from CPAN, which
|
|---|
| 459 | contains additional documentation.
|
|---|
| 460 |
|
|---|
| 461 | NOTE: This is an experimental feature. Details are subject to change.
|
|---|
| 462 |
|
|---|
| 463 | =head2 Binary numbers supported
|
|---|
| 464 |
|
|---|
| 465 | Binary numbers are now supported as literals, in s?printf formats, and
|
|---|
| 466 | C<oct()>:
|
|---|
| 467 |
|
|---|
| 468 | $answer = 0b101010;
|
|---|
| 469 | printf "The answer is: %b\n", oct("0b101010");
|
|---|
| 470 |
|
|---|
| 471 | =head2 Lvalue subroutines
|
|---|
| 472 |
|
|---|
| 473 | Subroutines can now return modifiable lvalues.
|
|---|
| 474 | See L<perlsub/"Lvalue subroutines">.
|
|---|
| 475 |
|
|---|
| 476 | NOTE: This is an experimental feature. Details are subject to change.
|
|---|
| 477 |
|
|---|
| 478 | =head2 Some arrows may be omitted in calls through references
|
|---|
| 479 |
|
|---|
| 480 | Perl now allows the arrow to be omitted in many constructs
|
|---|
| 481 | involving subroutine calls through references. For example,
|
|---|
| 482 | C<< $foo[10]->('foo') >> may now be written C<$foo[10]('foo')>.
|
|---|
| 483 | This is rather similar to how the arrow may be omitted from
|
|---|
| 484 | C<< $foo[10]->{'foo'} >>. Note however, that the arrow is still
|
|---|
| 485 | required for C<< foo(10)->('bar') >>.
|
|---|
| 486 |
|
|---|
| 487 | =head2 Boolean assignment operators are legal lvalues
|
|---|
| 488 |
|
|---|
| 489 | Constructs such as C<($a ||= 2) += 1> are now allowed.
|
|---|
| 490 |
|
|---|
| 491 | =head2 exists() is supported on subroutine names
|
|---|
| 492 |
|
|---|
| 493 | The exists() builtin now works on subroutine names. A subroutine
|
|---|
| 494 | is considered to exist if it has been declared (even if implicitly).
|
|---|
| 495 | See L<perlfunc/exists> for examples.
|
|---|
| 496 |
|
|---|
| 497 | =head2 exists() and delete() are supported on array elements
|
|---|
| 498 |
|
|---|
| 499 | The exists() and delete() builtins now work on simple arrays as well.
|
|---|
| 500 | The behavior is similar to that on hash elements.
|
|---|
| 501 |
|
|---|
| 502 | exists() can be used to check whether an array element has been
|
|---|
| 503 | initialized. This avoids autovivifying array elements that don't exist.
|
|---|
| 504 | If the array is tied, the EXISTS() method in the corresponding tied
|
|---|
| 505 | package will be invoked.
|
|---|
| 506 |
|
|---|
| 507 | delete() may be used to remove an element from the array and return
|
|---|
| 508 | it. The array element at that position returns to its uninitialized
|
|---|
| 509 | state, so that testing for the same element with exists() will return
|
|---|
| 510 | false. If the element happens to be the one at the end, the size of
|
|---|
| 511 | the array also shrinks up to the highest element that tests true for
|
|---|
| 512 | exists(), or 0 if none such is found. If the array is tied, the DELETE()
|
|---|
| 513 | method in the corresponding tied package will be invoked.
|
|---|
| 514 |
|
|---|
| 515 | See L<perlfunc/exists> and L<perlfunc/delete> for examples.
|
|---|
| 516 |
|
|---|
| 517 | =head2 Pseudo-hashes work better
|
|---|
| 518 |
|
|---|
| 519 | Dereferencing some types of reference values in a pseudo-hash,
|
|---|
| 520 | such as C<< $ph->{foo}[1] >>, was accidentally disallowed. This has
|
|---|
| 521 | been corrected.
|
|---|
| 522 |
|
|---|
| 523 | When applied to a pseudo-hash element, exists() now reports whether
|
|---|
| 524 | the specified value exists, not merely if the key is valid.
|
|---|
| 525 |
|
|---|
| 526 | delete() now works on pseudo-hashes. When given a pseudo-hash element
|
|---|
| 527 | or slice it deletes the values corresponding to the keys (but not the keys
|
|---|
| 528 | themselves). See L<perlref/"Pseudo-hashes: Using an array as a hash">.
|
|---|
| 529 |
|
|---|
| 530 | Pseudo-hash slices with constant keys are now optimized to array lookups
|
|---|
| 531 | at compile-time.
|
|---|
| 532 |
|
|---|
| 533 | List assignments to pseudo-hash slices are now supported.
|
|---|
| 534 |
|
|---|
| 535 | The C<fields> pragma now provides ways to create pseudo-hashes, via
|
|---|
| 536 | fields::new() and fields::phash(). See L<fields>.
|
|---|
| 537 |
|
|---|
| 538 | NOTE: The pseudo-hash data type continues to be experimental.
|
|---|
| 539 | Limiting oneself to the interface elements provided by the
|
|---|
| 540 | fields pragma will provide protection from any future changes.
|
|---|
| 541 |
|
|---|
| 542 | =head2 Automatic flushing of output buffers
|
|---|
| 543 |
|
|---|
| 544 | fork(), exec(), system(), qx//, and pipe open()s now flush buffers
|
|---|
| 545 | of all files opened for output when the operation was attempted. This
|
|---|
| 546 | mostly eliminates confusing buffering mishaps suffered by users unaware
|
|---|
| 547 | of how Perl internally handles I/O.
|
|---|
| 548 |
|
|---|
| 549 | This is not supported on some platforms like Solaris where a suitably
|
|---|
| 550 | correct implementation of fflush(NULL) isn't available.
|
|---|
| 551 |
|
|---|
| 552 | =head2 Better diagnostics on meaningless filehandle operations
|
|---|
| 553 |
|
|---|
| 554 | Constructs such as C<< open(<FH>) >> and C<< close(<FH>) >>
|
|---|
| 555 | are compile time errors. Attempting to read from filehandles that
|
|---|
| 556 | were opened only for writing will now produce warnings (just as
|
|---|
| 557 | writing to read-only filehandles does).
|
|---|
| 558 |
|
|---|
| 559 | =head2 Where possible, buffered data discarded from duped input filehandle
|
|---|
| 560 |
|
|---|
| 561 | C<< open(NEW, "<&OLD") >> now attempts to discard any data that
|
|---|
| 562 | was previously read and buffered in C<OLD> before duping the handle.
|
|---|
| 563 | On platforms where doing this is allowed, the next read operation
|
|---|
| 564 | on C<NEW> will return the same data as the corresponding operation
|
|---|
| 565 | on C<OLD>. Formerly, it would have returned the data from the start
|
|---|
| 566 | of the following disk block instead.
|
|---|
| 567 |
|
|---|
| 568 | =head2 eof() has the same old magic as <>
|
|---|
| 569 |
|
|---|
| 570 | C<eof()> would return true if no attempt to read from C<< <> >> had
|
|---|
| 571 | yet been made. C<eof()> has been changed to have a little magic of its
|
|---|
| 572 | own, it now opens the C<< <> >> files.
|
|---|
| 573 |
|
|---|
| 574 | =head2 binmode() can be used to set :crlf and :raw modes
|
|---|
| 575 |
|
|---|
| 576 | binmode() now accepts a second argument that specifies a discipline
|
|---|
| 577 | for the handle in question. The two pseudo-disciplines ":raw" and
|
|---|
| 578 | ":crlf" are currently supported on DOS-derivative platforms.
|
|---|
| 579 | See L<perlfunc/"binmode"> and L<open>.
|
|---|
| 580 |
|
|---|
| 581 | =head2 C<-T> filetest recognizes UTF-8 encoded files as "text"
|
|---|
| 582 |
|
|---|
| 583 | The algorithm used for the C<-T> filetest has been enhanced to
|
|---|
| 584 | correctly identify UTF-8 content as "text".
|
|---|
| 585 |
|
|---|
| 586 | =head2 system(), backticks and pipe open now reflect exec() failure
|
|---|
| 587 |
|
|---|
| 588 | On Unix and similar platforms, system(), qx() and open(FOO, "cmd |")
|
|---|
| 589 | etc., are implemented via fork() and exec(). When the underlying
|
|---|
| 590 | exec() fails, earlier versions did not report the error properly,
|
|---|
| 591 | since the exec() happened to be in a different process.
|
|---|
| 592 |
|
|---|
| 593 | The child process now communicates with the parent about the
|
|---|
| 594 | error in launching the external command, which allows these
|
|---|
| 595 | constructs to return with their usual error value and set $!.
|
|---|
| 596 |
|
|---|
| 597 | =head2 Improved diagnostics
|
|---|
| 598 |
|
|---|
| 599 | Line numbers are no longer suppressed (under most likely circumstances)
|
|---|
| 600 | during the global destruction phase.
|
|---|
| 601 |
|
|---|
| 602 | Diagnostics emitted from code running in threads other than the main
|
|---|
| 603 | thread are now accompanied by the thread ID.
|
|---|
| 604 |
|
|---|
| 605 | Embedded null characters in diagnostics now actually show up. They
|
|---|
| 606 | used to truncate the message in prior versions.
|
|---|
| 607 |
|
|---|
| 608 | $foo::a and $foo::b are now exempt from "possible typo" warnings only
|
|---|
| 609 | if sort() is encountered in package C<foo>.
|
|---|
| 610 |
|
|---|
| 611 | Unrecognized alphabetic escapes encountered when parsing quote
|
|---|
| 612 | constructs now generate a warning, since they may take on new
|
|---|
| 613 | semantics in later versions of Perl.
|
|---|
| 614 |
|
|---|
| 615 | Many diagnostics now report the internal operation in which the warning
|
|---|
| 616 | was provoked, like so:
|
|---|
| 617 |
|
|---|
| 618 | Use of uninitialized value in concatenation (.) at (eval 1) line 1.
|
|---|
| 619 | Use of uninitialized value in print at (eval 1) line 1.
|
|---|
| 620 |
|
|---|
| 621 | Diagnostics that occur within eval may also report the file and line
|
|---|
| 622 | number where the eval is located, in addition to the eval sequence
|
|---|
| 623 | number and the line number within the evaluated text itself. For
|
|---|
| 624 | example:
|
|---|
| 625 |
|
|---|
| 626 | Not enough arguments for scalar at (eval 4)[newlib/perl5db.pl:1411] line 2, at EOF
|
|---|
| 627 |
|
|---|
| 628 | =head2 Diagnostics follow STDERR
|
|---|
| 629 |
|
|---|
| 630 | Diagnostic output now goes to whichever file the C<STDERR> handle
|
|---|
| 631 | is pointing at, instead of always going to the underlying C runtime
|
|---|
| 632 | library's C<stderr>.
|
|---|
| 633 |
|
|---|
| 634 | =head2 More consistent close-on-exec behavior
|
|---|
| 635 |
|
|---|
| 636 | On systems that support a close-on-exec flag on filehandles, the
|
|---|
| 637 | flag is now set for any handles created by pipe(), socketpair(),
|
|---|
| 638 | socket(), and accept(), if that is warranted by the value of $^F
|
|---|
| 639 | that may be in effect. Earlier versions neglected to set the flag
|
|---|
| 640 | for handles created with these operators. See L<perlfunc/pipe>,
|
|---|
| 641 | L<perlfunc/socketpair>, L<perlfunc/socket>, L<perlfunc/accept>,
|
|---|
| 642 | and L<perlvar/$^F>.
|
|---|
| 643 |
|
|---|
| 644 | =head2 syswrite() ease-of-use
|
|---|
| 645 |
|
|---|
| 646 | The length argument of C<syswrite()> has become optional.
|
|---|
| 647 |
|
|---|
| 648 | =head2 Better syntax checks on parenthesized unary operators
|
|---|
| 649 |
|
|---|
| 650 | Expressions such as:
|
|---|
| 651 |
|
|---|
| 652 | print defined(&foo,&bar,&baz);
|
|---|
| 653 | print uc("foo","bar","baz");
|
|---|
| 654 | undef($foo,&bar);
|
|---|
| 655 |
|
|---|
| 656 | used to be accidentally allowed in earlier versions, and produced
|
|---|
| 657 | unpredictable behaviour. Some produced ancillary warnings
|
|---|
| 658 | when used in this way; others silently did the wrong thing.
|
|---|
| 659 |
|
|---|
| 660 | The parenthesized forms of most unary operators that expect a single
|
|---|
| 661 | argument now ensure that they are not called with more than one
|
|---|
| 662 | argument, making the cases shown above syntax errors. The usual
|
|---|
| 663 | behaviour of:
|
|---|
| 664 |
|
|---|
| 665 | print defined &foo, &bar, &baz;
|
|---|
| 666 | print uc "foo", "bar", "baz";
|
|---|
| 667 | undef $foo, &bar;
|
|---|
| 668 |
|
|---|
| 669 | remains unchanged. See L<perlop>.
|
|---|
| 670 |
|
|---|
| 671 | =head2 Bit operators support full native integer width
|
|---|
| 672 |
|
|---|
| 673 | The bit operators (& | ^ ~ << >>) now operate on the full native
|
|---|
| 674 | integral width (the exact size of which is available in $Config{ivsize}).
|
|---|
| 675 | For example, if your platform is either natively 64-bit or if Perl
|
|---|
| 676 | has been configured to use 64-bit integers, these operations apply
|
|---|
| 677 | to 8 bytes (as opposed to 4 bytes on 32-bit platforms).
|
|---|
| 678 | For portability, be sure to mask off the excess bits in the result of
|
|---|
| 679 | unary C<~>, e.g., C<~$x & 0xffffffff>.
|
|---|
| 680 |
|
|---|
| 681 | =head2 Improved security features
|
|---|
| 682 |
|
|---|
| 683 | More potentially unsafe operations taint their results for improved
|
|---|
| 684 | security.
|
|---|
| 685 |
|
|---|
| 686 | The C<passwd> and C<shell> fields returned by the getpwent(), getpwnam(),
|
|---|
| 687 | and getpwuid() are now tainted, because the user can affect their own
|
|---|
| 688 | encrypted password and login shell.
|
|---|
| 689 |
|
|---|
| 690 | The variable modified by shmread(), and messages returned by msgrcv()
|
|---|
| 691 | (and its object-oriented interface IPC::SysV::Msg::rcv) are also tainted,
|
|---|
| 692 | because other untrusted processes can modify messages and shared memory
|
|---|
| 693 | segments for their own nefarious purposes.
|
|---|
| 694 |
|
|---|
| 695 | =head2 More functional bareword prototype (*)
|
|---|
| 696 |
|
|---|
| 697 | Bareword prototypes have been rationalized to enable them to be used
|
|---|
| 698 | to override builtins that accept barewords and interpret them in
|
|---|
| 699 | a special way, such as C<require> or C<do>.
|
|---|
| 700 |
|
|---|
| 701 | Arguments prototyped as C<*> will now be visible within the subroutine
|
|---|
| 702 | as either a simple scalar or as a reference to a typeglob.
|
|---|
| 703 | See L<perlsub/Prototypes>.
|
|---|
| 704 |
|
|---|
| 705 | =head2 C<require> and C<do> may be overridden
|
|---|
| 706 |
|
|---|
| 707 | C<require> and C<do 'file'> operations may be overridden locally
|
|---|
| 708 | by importing subroutines of the same name into the current package
|
|---|
| 709 | (or globally by importing them into the CORE::GLOBAL:: namespace).
|
|---|
| 710 | Overriding C<require> will also affect C<use>, provided the override
|
|---|
| 711 | is visible at compile-time.
|
|---|
| 712 | See L<perlsub/"Overriding Built-in Functions">.
|
|---|
| 713 |
|
|---|
| 714 | =head2 $^X variables may now have names longer than one character
|
|---|
| 715 |
|
|---|
| 716 | Formerly, $^X was synonymous with ${"\cX"}, but $^XY was a syntax
|
|---|
| 717 | error. Now variable names that begin with a control character may be
|
|---|
| 718 | arbitrarily long. However, for compatibility reasons, these variables
|
|---|
| 719 | I<must> be written with explicit braces, as C<${^XY}> for example.
|
|---|
| 720 | C<${^XYZ}> is synonymous with ${"\cXYZ"}. Variable names with more
|
|---|
| 721 | than one control character, such as C<${^XY^Z}>, are illegal.
|
|---|
| 722 |
|
|---|
| 723 | The old syntax has not changed. As before, `^X' may be either a
|
|---|
| 724 | literal control-X character or the two-character sequence `caret' plus
|
|---|
| 725 | `X'. When braces are omitted, the variable name stops after the
|
|---|
| 726 | control character. Thus C<"$^XYZ"> continues to be synonymous with
|
|---|
| 727 | C<$^X . "YZ"> as before.
|
|---|
| 728 |
|
|---|
| 729 | As before, lexical variables may not have names beginning with control
|
|---|
| 730 | characters. As before, variables whose names begin with a control
|
|---|
| 731 | character are always forced to be in package `main'. All such variables
|
|---|
| 732 | are reserved for future extensions, except those that begin with
|
|---|
| 733 | C<^_>, which may be used by user programs and are guaranteed not to
|
|---|
| 734 | acquire special meaning in any future version of Perl.
|
|---|
| 735 |
|
|---|
| 736 | =head2 New variable $^C reflects C<-c> switch
|
|---|
| 737 |
|
|---|
| 738 | C<$^C> has a boolean value that reflects whether perl is being run
|
|---|
| 739 | in compile-only mode (i.e. via the C<-c> switch). Since
|
|---|
| 740 | BEGIN blocks are executed under such conditions, this variable
|
|---|
| 741 | enables perl code to determine whether actions that make sense
|
|---|
| 742 | only during normal running are warranted. See L<perlvar>.
|
|---|
| 743 |
|
|---|
| 744 | =head2 New variable $^V contains Perl version as a string
|
|---|
| 745 |
|
|---|
| 746 | C<$^V> contains the Perl version number as a string composed of
|
|---|
| 747 | characters whose ordinals match the version numbers, i.e. v5.6.0.
|
|---|
| 748 | This may be used in string comparisons.
|
|---|
| 749 |
|
|---|
| 750 | See C<Support for strings represented as a vector of ordinals> for an
|
|---|
| 751 | example.
|
|---|
| 752 |
|
|---|
| 753 | =head2 Optional Y2K warnings
|
|---|
| 754 |
|
|---|
| 755 | If Perl is built with the cpp macro C<PERL_Y2KWARN> defined,
|
|---|
| 756 | it emits optional warnings when concatenating the number 19
|
|---|
| 757 | with another number.
|
|---|
| 758 |
|
|---|
| 759 | This behavior must be specifically enabled when running Configure.
|
|---|
| 760 | See F<INSTALL> and F<README.Y2K>.
|
|---|
| 761 |
|
|---|
| 762 | =head2 Arrays now always interpolate into double-quoted strings
|
|---|
| 763 |
|
|---|
| 764 | In double-quoted strings, arrays now interpolate, no matter what. The
|
|---|
| 765 | behavior in earlier versions of perl 5 was that arrays would interpolate
|
|---|
| 766 | into strings if the array had been mentioned before the string was
|
|---|
| 767 | compiled, and otherwise Perl would raise a fatal compile-time error.
|
|---|
| 768 | In versions 5.000 through 5.003, the error was
|
|---|
| 769 |
|
|---|
| 770 | Literal @example now requires backslash
|
|---|
| 771 |
|
|---|
| 772 | In versions 5.004_01 through 5.6.0, the error was
|
|---|
| 773 |
|
|---|
| 774 | In string, @example now must be written as \@example
|
|---|
| 775 |
|
|---|
| 776 | The idea here was to get people into the habit of writing
|
|---|
| 777 | C<"fred\@example.com"> when they wanted a literal C<@> sign, just as
|
|---|
| 778 | they have always written C<"Give me back my \$5"> when they wanted a
|
|---|
| 779 | literal C<$> sign.
|
|---|
| 780 |
|
|---|
| 781 | Starting with 5.6.1, when Perl now sees an C<@> sign in a
|
|---|
| 782 | double-quoted string, it I<always> attempts to interpolate an array,
|
|---|
| 783 | regardless of whether or not the array has been used or declared
|
|---|
| 784 | already. The fatal error has been downgraded to an optional warning:
|
|---|
| 785 |
|
|---|
| 786 | Possible unintended interpolation of @example in string
|
|---|
| 787 |
|
|---|
| 788 | This warns you that C<"[email protected]"> is going to turn into
|
|---|
| 789 | C<fred.com> if you don't backslash the C<@>.
|
|---|
| 790 | See http://www.plover.com/~mjd/perl/at-error.html for more details
|
|---|
| 791 | about the history here.
|
|---|
| 792 |
|
|---|
| 793 | =head2 @- and @+ provide starting/ending offsets of regex matches
|
|---|
| 794 |
|
|---|
| 795 | The new magic variables @- and @+ provide the starting and ending
|
|---|
| 796 | offsets, respectively, of $&, $1, $2, etc. See L<perlvar> for
|
|---|
| 797 | details.
|
|---|
| 798 |
|
|---|
| 799 | =head1 Modules and Pragmata
|
|---|
| 800 |
|
|---|
| 801 | =head2 Modules
|
|---|
| 802 |
|
|---|
| 803 | =over 4
|
|---|
| 804 |
|
|---|
| 805 | =item attributes
|
|---|
| 806 |
|
|---|
| 807 | While used internally by Perl as a pragma, this module also
|
|---|
| 808 | provides a way to fetch subroutine and variable attributes.
|
|---|
| 809 | See L<attributes>.
|
|---|
| 810 |
|
|---|
| 811 | =item B
|
|---|
| 812 |
|
|---|
| 813 | The Perl Compiler suite has been extensively reworked for this
|
|---|
| 814 | release. More of the standard Perl testsuite passes when run
|
|---|
| 815 | under the Compiler, but there is still a significant way to
|
|---|
| 816 | go to achieve production quality compiled executables.
|
|---|
| 817 |
|
|---|
| 818 | NOTE: The Compiler suite remains highly experimental. The
|
|---|
| 819 | generated code may not be correct, even when it manages to execute
|
|---|
| 820 | without errors.
|
|---|
| 821 |
|
|---|
| 822 | =item Benchmark
|
|---|
| 823 |
|
|---|
| 824 | Overall, Benchmark results exhibit lower average error and better timing
|
|---|
| 825 | accuracy.
|
|---|
| 826 |
|
|---|
| 827 | You can now run tests for I<n> seconds instead of guessing the right
|
|---|
| 828 | number of tests to run: e.g., timethese(-5, ...) will run each
|
|---|
| 829 | code for at least 5 CPU seconds. Zero as the "number of repetitions"
|
|---|
| 830 | means "for at least 3 CPU seconds". The output format has also
|
|---|
| 831 | changed. For example:
|
|---|
| 832 |
|
|---|
| 833 | use Benchmark;$x=3;timethese(-5,{a=>sub{$x*$x},b=>sub{$x**2}})
|
|---|
| 834 |
|
|---|
| 835 | will now output something like this:
|
|---|
| 836 |
|
|---|
| 837 | Benchmark: running a, b, each for at least 5 CPU seconds...
|
|---|
| 838 | a: 5 wallclock secs ( 5.77 usr + 0.00 sys = 5.77 CPU) @ 200551.91/s (n=1156516)
|
|---|
| 839 | b: 4 wallclock secs ( 5.00 usr + 0.02 sys = 5.02 CPU) @ 159605.18/s (n=800686)
|
|---|
| 840 |
|
|---|
| 841 | New features: "each for at least N CPU seconds...", "wallclock secs",
|
|---|
| 842 | and the "@ operations/CPU second (n=operations)".
|
|---|
| 843 |
|
|---|
| 844 | timethese() now returns a reference to a hash of Benchmark objects containing
|
|---|
| 845 | the test results, keyed on the names of the tests.
|
|---|
| 846 |
|
|---|
| 847 | timethis() now returns the iterations field in the Benchmark result object
|
|---|
| 848 | instead of 0.
|
|---|
| 849 |
|
|---|
| 850 | timethese(), timethis(), and the new cmpthese() (see below) can also take
|
|---|
| 851 | a format specifier of 'none' to suppress output.
|
|---|
| 852 |
|
|---|
| 853 | A new function countit() is just like timeit() except that it takes a
|
|---|
| 854 | TIME instead of a COUNT.
|
|---|
| 855 |
|
|---|
| 856 | A new function cmpthese() prints a chart comparing the results of each test
|
|---|
| 857 | returned from a timethese() call. For each possible pair of tests, the
|
|---|
| 858 | percentage speed difference (iters/sec or seconds/iter) is shown.
|
|---|
| 859 |
|
|---|
| 860 | For other details, see L<Benchmark>.
|
|---|
| 861 |
|
|---|
| 862 | =item ByteLoader
|
|---|
| 863 |
|
|---|
| 864 | The ByteLoader is a dedicated extension to generate and run
|
|---|
| 865 | Perl bytecode. See L<ByteLoader>.
|
|---|
| 866 |
|
|---|
| 867 | =item constant
|
|---|
| 868 |
|
|---|
| 869 | References can now be used.
|
|---|
| 870 |
|
|---|
| 871 | The new version also allows a leading underscore in constant names, but
|
|---|
| 872 | disallows a double leading underscore (as in "__LINE__"). Some other names
|
|---|
| 873 | are disallowed or warned against, including BEGIN, END, etc. Some names
|
|---|
| 874 | which were forced into main:: used to fail silently in some cases; now they're
|
|---|
| 875 | fatal (outside of main::) and an optional warning (inside of main::).
|
|---|
| 876 | The ability to detect whether a constant had been set with a given name has
|
|---|
| 877 | been added.
|
|---|
| 878 |
|
|---|
| 879 | See L<constant>.
|
|---|
| 880 |
|
|---|
| 881 | =item charnames
|
|---|
| 882 |
|
|---|
| 883 | This pragma implements the C<\N> string escape. See L<charnames>.
|
|---|
| 884 |
|
|---|
| 885 | =item Data::Dumper
|
|---|
| 886 |
|
|---|
| 887 | A C<Maxdepth> setting can be specified to avoid venturing
|
|---|
| 888 | too deeply into deep data structures. See L<Data::Dumper>.
|
|---|
| 889 |
|
|---|
| 890 | The XSUB implementation of Dump() is now automatically called if the
|
|---|
| 891 | C<Useqq> setting is not in use.
|
|---|
| 892 |
|
|---|
| 893 | Dumping C<qr//> objects works correctly.
|
|---|
| 894 |
|
|---|
| 895 | =item DB
|
|---|
| 896 |
|
|---|
| 897 | C<DB> is an experimental module that exposes a clean abstraction
|
|---|
| 898 | to Perl's debugging API.
|
|---|
| 899 |
|
|---|
| 900 | =item DB_File
|
|---|
| 901 |
|
|---|
| 902 | DB_File can now be built with Berkeley DB versions 1, 2 or 3.
|
|---|
| 903 | See C<ext/DB_File/Changes>.
|
|---|
| 904 |
|
|---|
| 905 | =item Devel::DProf
|
|---|
| 906 |
|
|---|
| 907 | Devel::DProf, a Perl source code profiler has been added. See
|
|---|
| 908 | L<Devel::DProf> and L<dprofpp>.
|
|---|
| 909 |
|
|---|
| 910 | =item Devel::Peek
|
|---|
| 911 |
|
|---|
| 912 | The Devel::Peek module provides access to the internal representation
|
|---|
| 913 | of Perl variables and data. It is a data debugging tool for the XS programmer.
|
|---|
| 914 |
|
|---|
| 915 | =item Dumpvalue
|
|---|
| 916 |
|
|---|
| 917 | The Dumpvalue module provides screen dumps of Perl data.
|
|---|
| 918 |
|
|---|
| 919 | =item DynaLoader
|
|---|
| 920 |
|
|---|
| 921 | DynaLoader now supports a dl_unload_file() function on platforms that
|
|---|
| 922 | support unloading shared objects using dlclose().
|
|---|
| 923 |
|
|---|
| 924 | Perl can also optionally arrange to unload all extension shared objects
|
|---|
| 925 | loaded by Perl. To enable this, build Perl with the Configure option
|
|---|
| 926 | C<-Accflags=-DDL_UNLOAD_ALL_AT_EXIT>. (This maybe useful if you are
|
|---|
| 927 | using Apache with mod_perl.)
|
|---|
| 928 |
|
|---|
| 929 | =item English
|
|---|
| 930 |
|
|---|
| 931 | $PERL_VERSION now stands for C<$^V> (a string value) rather than for C<$]>
|
|---|
| 932 | (a numeric value).
|
|---|
| 933 |
|
|---|
| 934 | =item Env
|
|---|
| 935 |
|
|---|
| 936 | Env now supports accessing environment variables like PATH as array
|
|---|
| 937 | variables.
|
|---|
| 938 |
|
|---|
| 939 | =item Fcntl
|
|---|
| 940 |
|
|---|
| 941 | More Fcntl constants added: F_SETLK64, F_SETLKW64, O_LARGEFILE for
|
|---|
| 942 | large file (more than 4GB) access (NOTE: the O_LARGEFILE is
|
|---|
| 943 | automatically added to sysopen() flags if large file support has been
|
|---|
| 944 | configured, as is the default), Free/Net/OpenBSD locking behaviour
|
|---|
| 945 | flags F_FLOCK, F_POSIX, Linux F_SHLCK, and O_ACCMODE: the combined
|
|---|
| 946 | mask of O_RDONLY, O_WRONLY, and O_RDWR. The seek()/sysseek()
|
|---|
| 947 | constants SEEK_SET, SEEK_CUR, and SEEK_END are available via the
|
|---|
| 948 | C<:seek> tag. The chmod()/stat() S_IF* constants and S_IS* functions
|
|---|
| 949 | are available via the C<:mode> tag.
|
|---|
| 950 |
|
|---|
| 951 | =item File::Compare
|
|---|
| 952 |
|
|---|
| 953 | A compare_text() function has been added, which allows custom
|
|---|
| 954 | comparison functions. See L<File::Compare>.
|
|---|
| 955 |
|
|---|
| 956 | =item File::Find
|
|---|
| 957 |
|
|---|
| 958 | File::Find now works correctly when the wanted() function is either
|
|---|
| 959 | autoloaded or is a symbolic reference.
|
|---|
| 960 |
|
|---|
| 961 | A bug that caused File::Find to lose track of the working directory
|
|---|
| 962 | when pruning top-level directories has been fixed.
|
|---|
| 963 |
|
|---|
| 964 | File::Find now also supports several other options to control its
|
|---|
| 965 | behavior. It can follow symbolic links if the C<follow> option is
|
|---|
| 966 | specified. Enabling the C<no_chdir> option will make File::Find skip
|
|---|
| 967 | changing the current directory when walking directories. The C<untaint>
|
|---|
| 968 | flag can be useful when running with taint checks enabled.
|
|---|
| 969 |
|
|---|
| 970 | See L<File::Find>.
|
|---|
| 971 |
|
|---|
| 972 | =item File::Glob
|
|---|
| 973 |
|
|---|
| 974 | This extension implements BSD-style file globbing. By default,
|
|---|
| 975 | it will also be used for the internal implementation of the glob()
|
|---|
| 976 | operator. See L<File::Glob>.
|
|---|
| 977 |
|
|---|
| 978 | =item File::Spec
|
|---|
| 979 |
|
|---|
| 980 | New methods have been added to the File::Spec module: devnull() returns
|
|---|
| 981 | the name of the null device (/dev/null on Unix) and tmpdir() the name of
|
|---|
| 982 | the temp directory (normally /tmp on Unix). There are now also methods
|
|---|
| 983 | to convert between absolute and relative filenames: abs2rel() and
|
|---|
| 984 | rel2abs(). For compatibility with operating systems that specify volume
|
|---|
| 985 | names in file paths, the splitpath(), splitdir(), and catdir() methods
|
|---|
| 986 | have been added.
|
|---|
| 987 |
|
|---|
| 988 | =item File::Spec::Functions
|
|---|
| 989 |
|
|---|
| 990 | The new File::Spec::Functions modules provides a function interface
|
|---|
| 991 | to the File::Spec module. Allows shorthand
|
|---|
| 992 |
|
|---|
| 993 | $fullname = catfile($dir1, $dir2, $file);
|
|---|
| 994 |
|
|---|
| 995 | instead of
|
|---|
| 996 |
|
|---|
| 997 | $fullname = File::Spec->catfile($dir1, $dir2, $file);
|
|---|
| 998 |
|
|---|
| 999 | =item Getopt::Long
|
|---|
| 1000 |
|
|---|
| 1001 | Getopt::Long licensing has changed to allow the Perl Artistic License
|
|---|
| 1002 | as well as the GPL. It used to be GPL only, which got in the way of
|
|---|
| 1003 | non-GPL applications that wanted to use Getopt::Long.
|
|---|
| 1004 |
|
|---|
| 1005 | Getopt::Long encourages the use of Pod::Usage to produce help
|
|---|
| 1006 | messages. For example:
|
|---|
| 1007 |
|
|---|
| 1008 | use Getopt::Long;
|
|---|
| 1009 | use Pod::Usage;
|
|---|
| 1010 | my $man = 0;
|
|---|
| 1011 | my $help = 0;
|
|---|
| 1012 | GetOptions('help|?' => \$help, man => \$man) or pod2usage(2);
|
|---|
| 1013 | pod2usage(1) if $help;
|
|---|
| 1014 | pod2usage(-exitstatus => 0, -verbose => 2) if $man;
|
|---|
| 1015 |
|
|---|
| 1016 | __END__
|
|---|
| 1017 |
|
|---|
| 1018 | =head1 NAME
|
|---|
| 1019 |
|
|---|
| 1020 | sample - Using Getopt::Long and Pod::Usage
|
|---|
| 1021 |
|
|---|
| 1022 | =head1 SYNOPSIS
|
|---|
| 1023 |
|
|---|
| 1024 | sample [options] [file ...]
|
|---|
| 1025 |
|
|---|
| 1026 | Options:
|
|---|
| 1027 | -help brief help message
|
|---|
| 1028 | -man full documentation
|
|---|
| 1029 |
|
|---|
| 1030 | =head1 OPTIONS
|
|---|
| 1031 |
|
|---|
| 1032 | =over 8
|
|---|
| 1033 |
|
|---|
| 1034 | =item B<-help>
|
|---|
| 1035 |
|
|---|
| 1036 | Print a brief help message and exits.
|
|---|
| 1037 |
|
|---|
| 1038 | =item B<-man>
|
|---|
| 1039 |
|
|---|
| 1040 | Prints the manual page and exits.
|
|---|
| 1041 |
|
|---|
| 1042 | =back
|
|---|
| 1043 |
|
|---|
| 1044 | =head1 DESCRIPTION
|
|---|
| 1045 |
|
|---|
| 1046 | B<This program> will read the given input file(s) and do something
|
|---|
| 1047 | useful with the contents thereof.
|
|---|
| 1048 |
|
|---|
| 1049 | =cut
|
|---|
| 1050 |
|
|---|
| 1051 | See L<Pod::Usage> for details.
|
|---|
| 1052 |
|
|---|
| 1053 | A bug that prevented the non-option call-back <> from being
|
|---|
| 1054 | specified as the first argument has been fixed.
|
|---|
| 1055 |
|
|---|
| 1056 | To specify the characters < and > as option starters, use ><. Note,
|
|---|
| 1057 | however, that changing option starters is strongly deprecated.
|
|---|
| 1058 |
|
|---|
| 1059 | =item IO
|
|---|
| 1060 |
|
|---|
| 1061 | write() and syswrite() will now accept a single-argument
|
|---|
| 1062 | form of the call, for consistency with Perl's syswrite().
|
|---|
| 1063 |
|
|---|
| 1064 | You can now create a TCP-based IO::Socket::INET without forcing
|
|---|
| 1065 | a connect attempt. This allows you to configure its options
|
|---|
| 1066 | (like making it non-blocking) and then call connect() manually.
|
|---|
| 1067 |
|
|---|
| 1068 | A bug that prevented the IO::Socket::protocol() accessor
|
|---|
| 1069 | from ever returning the correct value has been corrected.
|
|---|
| 1070 |
|
|---|
| 1071 | IO::Socket::connect now uses non-blocking IO instead of alarm()
|
|---|
| 1072 | to do connect timeouts.
|
|---|
| 1073 |
|
|---|
| 1074 | IO::Socket::accept now uses select() instead of alarm() for doing
|
|---|
| 1075 | timeouts.
|
|---|
| 1076 |
|
|---|
| 1077 | IO::Socket::INET->new now sets $! correctly on failure. $@ is
|
|---|
| 1078 | still set for backwards compatibility.
|
|---|
| 1079 |
|
|---|
| 1080 | =item JPL
|
|---|
| 1081 |
|
|---|
| 1082 | Java Perl Lingo is now distributed with Perl. See jpl/README
|
|---|
| 1083 | for more information.
|
|---|
| 1084 |
|
|---|
| 1085 | =item lib
|
|---|
| 1086 |
|
|---|
| 1087 | C<use lib> now weeds out any trailing duplicate entries.
|
|---|
| 1088 | C<no lib> removes all named entries.
|
|---|
| 1089 |
|
|---|
| 1090 | =item Math::BigInt
|
|---|
|
|---|