Fix example #4 in perlXStut
[p5sagit/p5-mst-13.2.git] / pod / perlnews.pod
CommitLineData
5f05dabc 1=head1 NAME
2
3perlnews - what's new for perl5.004
4
5=head1 DESCRIPTION
6
7This document describes differences between the 5.003 release (as
8documented in I<Programming Perl>, second edition--the Camel Book) and
9this one.
10
11=head1 Supported Environments
12
13Perl5.004 builds out of the box on Unix, Plan9, LynxOS, VMS, OS/2,
14QNX, and AmigaOS.
15
16=head1 Core Changes
17
18Most importantly, many bugs were fixed. See the F<Changes>
19file in the distribution for details.
20
21=head2 Compilation Option: Binary Compatibility With 5.003
22
23There is a new Configure question that asks if you want to maintain
24binary compatibility with Perl 5.003. If you choose binary
25compatibility, you do not have to recompile your extensions, but you
26might have symbol conflicts if you embed Perl in another application.
27
7cfe7857 28=head2 New Opcode Module and Revised Safe Module
29
30A new Opcode module supports the creation, manipulation and
31application of opcode masks. The revised Safe module has a new API
32and is implemented using the new Opcode module. Please read the new
33Opcode and Safe documentation.
34
5f05dabc 35=head2 Internal Change: FileHandle Deprecated
36
37Filehandles are now stored internally as type IO::Handle.
38Although C<use FileHandle> and C<*STDOUT{FILEHANDLE}>
39are still supported for backwards compatibility
40C<use IO::Handle> (or C<IO::Seekable> or C<IO::File>) and
41C<*STDOUT{IO}> are the way of the future.
42
28757baa 43=head2 Internal Change: PerlIO internal IO abstraction interface
5f05dabc 44
45It is now possible to build Perl with AT&T's sfio IO package
46instead of stdio. See L<perlapio> for more details, and
47the F<INSTALL> file for how to use it.
48
49=head2 New and Changed Built-in Variables
50
51=over
52
53=item $^E
54
55Extended error message under some platforms ($EXTENDED_OS_ERROR
56if you C<use English>).
57
58=item $^H
59
60The current set of syntax checks enabled by C<use strict>. See the
61documentation of C<strict> for more details. Not actually new, but
62newly documented.
63Because it is intended for internal use by Perl core components,
64there is no C<use English> long name for this variable.
65
66=item $^M
67
68By default, running out of memory it is not trappable. However, if
69compiled for this, Perl may use the contents of C<$^M> as an emergency
70pool after die()ing with this message. Suppose that your Perl were
71compiled with -DEMERGENCY_SBRK and used Perl's malloc. Then
72
73 $^M = 'a' x (1<<16);
74
75would allocate 64K buffer for use when in emergency.
76See the F<INSTALL> file for information on how to enable this option.
77As a disincentive to casual use of this advanced feature,
78there is no C<use English> long name for this variable.
79
80=back
81
82=head2 New and Changed Built-in Functions
83
84=over
85
86=item delete on slices
87
88This now works. (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
89
90=item flock
91
92is now supported on more platforms, and prefers fcntl
93to lockf when emulating.
94
95=item keys as an lvalue
96
97As an lvalue, C<keys> allows you to increase the number of hash buckets
98allocated for the given associative array. This can gain you a measure
99of efficiency if you know the hash is going to get big. (This is
100similar to pre-extending an array by assigning a larger number to
101$#array.) If you say
102
103 keys %hash = 200;
104
105then C<%hash> will have at least 200 buckets allocated for it. These
106buckets will be retained even if you do C<%hash = ()>; use C<undef
107%hash> if you want to free the storage while C<%hash> is still in scope.
108You can't shrink the number of buckets allocated for the hash using
109C<keys> in this way (but you needn't worry about doing this by accident,
110as trying has no effect).
111
112=item my() in Control Structures
113
114You can now use my() (with or without the parentheses) in the control
115expressions of control structures such as:
116
117 while (my $line = <>) {
118 $line = lc $line;
119 } continue {
120 print $line;
121 }
122
123 if ((my $answer = <STDIN>) =~ /^yes$/i) {
124 user_agrees();
125 } elsif ($answer =~ /^no$/i) {
126 user_disagrees();
127 } else {
128 chomp $answer;
129 die "'$answer' is neither 'yes' nor 'no'";
130 }
131
132Also, you can declare a foreach loop control variable as lexical by
133preceding it with the word "my". For example, in:
134
135 foreach my $i (1, 2, 3) {
136 some_function();
137 }
138
139$i is a lexical variable, and the scope of $i extends to the end of
140the loop, but not beyond it.
141
142Note that you still cannot use my() on global punctuation variables
143such as $_ and the like.
144
145=item unpack() and pack()
146
147A new format 'w' represents a BER compressed integer (as defined in
148ASN.1). Its format is a sequence of one or more bytes, each of which
149provides seven bits of the total value, with the most significant
150first. Bit eight of each byte is set, except for the last byte, in
151which bit eight is clear.
152
153=item use VERSION
154
155If the first argument to C<use> is a number, it is treated as a version
156number instead of a module name. If the version of the Perl interpreter
157is less than VERSION, then an error message is printed and Perl exits
158immediately. This is often useful if you need to check the current
159Perl version before C<use>ing library modules which have changed in
160incompatible ways from older versions of Perl. (We try not to do
161this more than we have to.)
162
163=item use Module VERSION LIST
164
165If the VERSION argument is present between Module and LIST, then the
71be2cbc 166C<use> will call the VERSION method in class Module with the given
167version as an argument. The default VERSION method, inherited from
168the Universal class, croaks if the given version is larger than the
169value of the variable $Module::VERSION. (Note that there is not a
170comma after VERSION!)
5f05dabc 171
7cfe7857 172This version-checking mechanism is similar to the one currently used
173in the Exporter module, but it is faster and can be used with modules
174that don't use the Exporter. It is the recommended method for new
175code.
176
5f05dabc 177=item prototype(FUNCTION)
178
179Returns the prototype of a function as a string (or C<undef> if the
180function has no prototype). FUNCTION is a reference to or the name of the
181function whose prototype you want to retrieve.
182(Not actually new; just never documented before.)
183
184=item $_ as Default
185
186Functions documented in the Camel to default to $_ now in
187fact do, and all those that do are so documented in L<perlfunc>.
188
189=back
190
191=head2 New Built-in Methods
192
193The C<UNIVERSAL> package automatically contains the following methods that
194are inherited by all other classes:
195
196=over 4
197
198=item isa(CLASS)
199
200C<isa> returns I<true> if its object is blessed into a sub-class of C<CLASS>
201
202C<isa> is also exportable and can be called as a sub with two arguments. This
203allows the ability to check what a reference points to. Example:
204
205 use UNIVERSAL qw(isa);
206
207 if(isa($ref, 'ARRAY')) {
208 ...
209 }
210
211=item can(METHOD)
212
213C<can> checks to see if its object has a method called C<METHOD>,
214if it does then a reference to the sub is returned; if it does not then
215I<undef> is returned.
216
217=item VERSION( [NEED] )
218
71be2cbc 219C<VERSION> returns the version number of the class (package). If the
220NEED argument is given then it will check that the current version (as
221defined by the $VERSION variable in the given package) not less than
222NEED; it will die if this is not the case. This method is normally
223called as a class method. This method is called automatically by the
224C<VERSION> form of C<use>.
5f05dabc 225
226 use A 1.2 qw(some imported subs);
71be2cbc 227 # implies:
228 A->VERSION(1.2);
5f05dabc 229
230=item class()
231
232C<class> returns the class name of its object.
233
234=item is_instance()
235
236C<is_instance> returns true if its object is an instance of some
237class, false if its object is the class (package) itself. Example
238
239 A->is_instance(); # False
240
241 $var = 'A';
242 $var->is_instance(); # False
243
244 $ref = bless [], 'A';
245 $ref->is_instance(); # True
246
247=back
248
249B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
250C<isa> uses a very similar method and cache-ing strategy. This may cause
251strange effects if the Perl code dynamically changes @ISA in any package.
252
253You may add other methods to the UNIVERSAL class via Perl or XS code.
254You do not need to C<use UNIVERSAL> in order to make these methods
255available to your program. This is necessary only if you wish to
256have C<isa> available as a plain subroutine in the current package.
257
258=head2 TIEHANDLE Now Supported
259
260=over
261
262=item TIEHANDLE classname, LIST
263
264This is the constructor for the class. That means it is expected to
265return an object of some sort. The reference can be used to
266hold some internal information.
267
268 sub TIEHANDLE { print "<shout>\n"; my $i; bless \$i, shift }
269
270=item PRINT this, LIST
271
272This method will be triggered every time the tied handle is printed to.
273Beyond its self reference it also expects the list that was passed to
274the print function.
275
276 sub PRINT { $r = shift; $$r++; print join($,,map(uc($_),@_)),$\ }
277
278=item READLINE this
279
280This method will be called when the handle is read from. The method
281should return undef when there is no more data.
282
283 sub READLINE { $r = shift; "PRINT called $$r times\n"; }
284
285=item DESTROY this
286
287As with the other types of ties, this method will be called when the
288tied handle is about to be destroyed. This is useful for debugging and
289possibly for cleaning up.
290
291 sub DESTROY { print "</shout>\n" }
292
293=back
294
295=head1 Pragmata
296
297Three new pragmatic modules exist:
298
299=over
300
301=item use blib
302
303Looks for MakeMaker-like I<'blib'> directory structure starting in
304I<dir> (or current directory) and working back up to five levels of
305parent directories.
306
307Intended for use on command line with B<-M> option as a way of testing
308arbitrary scripts against an uninstalled version of a package.
309
310=item use locale
311
312Tells the compiler to enable (or disable) the use of POSIX locales for
313built-in operations.
314
315When C<use locale> is in effect, the current LC_CTYPE locale is used
316for regular expressions and case mapping; LC_COLLATE for string
317ordering; and LC_NUMERIC for numeric formating in printf and sprintf
318(but B<not> in print). LC_NUMERIC is always used in write, since
319lexical scoping of formats is problematic at best.
320
321Each C<use locale> or C<no locale> affects statements to the end of
322the enclosing BLOCK or, if not inside a BLOCK, to the end of the
323current file. Locales can be switched and queried with
324POSIX::setlocale().
325
326See L<perllocale> for more information.
327
328=item use ops
329
7cfe7857 330Disable unsafe opcodes, or any named opcodes, when compiling Perl code.
5f05dabc 331
332=back
333
334=head1 Modules
335
336=head2 Module Information Summary
337
338Brand new modules:
339
340 IO.pm Top-level interface to IO::* classes
341 IO/File.pm IO::File extension Perl module
342 IO/Handle.pm IO::Handle extension Perl module
343 IO/Pipe.pm IO::Pipe extension Perl module
344 IO/Seekable.pm IO::Seekable extension Perl module
345 IO/Select.pm IO::Select extension Perl module
346 IO/Socket.pm IO::Socket extension Perl module
347
348 Opcode.pm Disable named opcodes when compiling Perl code
349
350 ExtUtils/Embed.pm Utilities for embedding Perl in C programs
351 ExtUtils/testlib.pm Fixes up @INC to use just-built extension
352
353 Fatal.pm Make do-or-die equivalents of functions
354 FindBin.pm Find path of currently executing program
355
356 Class/Template.pm Structure/member template builder
357 File/stat.pm Object-oriented wrapper around CORE::stat
358 Net/hostent.pm Object-oriented wrapper around CORE::gethost*
359 Net/netent.pm Object-oriented wrapper around CORE::getnet*
360 Net/protoent.pm Object-oriented wrapper around CORE::getproto*
361 Net/servent.pm Object-oriented wrapper around CORE::getserv*
362 Time/gmtime.pm Object-oriented wrapper around CORE::gmtime
363 Time/localtime.pm Object-oriented wrapper around CORE::localtime
364 Time/tm.pm Perl implementation of "struct tm" for {gm,local}time
365 User/grent.pm Object-oriented wrapper around CORE::getgr*
366 User/pwent.pm Object-oriented wrapper around CORE::getpw*
367
7a4c00b4 368 lib/Tie/RefHash.pm Base class for tied hashes with references as keys
369
5f05dabc 370 UNIVERSAL.pm Base class for *ALL* classes
371
372=head2 IO
373
374The IO module provides a simple mechanism to load all of the IO modules at one
375go. Currently this includes:
376
377 IO::Handle
378 IO::Seekable
379 IO::File
380 IO::Pipe
381 IO::Socket
382
383For more information on any of these modules, please see its
384respective documentation.
385
386=head2 Math::Complex
387
388The Math::Complex module has been totally rewritten, and now supports
389more operations. These are overloaded:
390
391 + - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
392
393And these functions are now exported:
394
395 pi i Re Im arg
396 log10 logn cbrt root
397 tan cotan asin acos atan acotan
398 sinh cosh tanh cotanh asinh acosh atanh acotanh
399 cplx cplxe
400
401=head2 Overridden Built-ins
402
403Many of the Perl built-ins returning lists now have
404object-oriented overrides. These are:
405
406 File::stat
407 Net::hostent
408 Net::netent
409 Net::protoent
410 Net::servent
411 Time::gmtime
412 Time::localtime
413 User::grent
414 User::pwent
415
416For example, you can now say
417
418 use File::stat;
419 use User::pwent;
420 $his = (stat($filename)->st_uid == pwent($whoever)->pw_uid);
421
422=head1 Efficiency Enhancements
423
424All hash keys with the same string are only allocated once, so
425even if you have 100 copies of the same hash, the immutable keys
426never have to be re-allocated.
427
7cfe7857 428Functions that have an empty prototype and that do nothing but return
429a fixed value are now inlined (e.g. C<sub PI () { 3.14159 }>).
5f05dabc 430
431=head1 Documentation Changes
432
433Many of the base and library pods were updated. These
434new pods are included in section 1:
435
436=over 4
437
71be2cbc 438=item L<perlnews>
5f05dabc 439
71be2cbc 440This document.
5f05dabc 441
71be2cbc 442=item L<perllocale>
5f05dabc 443
71be2cbc 444Locale support (internationalization and localization).
5f05dabc 445
446=item L<perltoot>
447
448Tutorial on Perl OO programming.
449
71be2cbc 450=item L<perlapio>
451
452Perl internal IO abstraction interface.
453
5f05dabc 454=item L<perldebug>
455
456Although not new, this has been massively updated.
457
458=item L<perlsec>
459
460Although not new, this has been massively updated.
461
462=back
463
464=head1 New Diagnostics
465
466Several new conditions will trigger warnings that were
467silent before. Some only affect certain platforms.
468The following new warnings and errors
469outline these:
470
471=over 4
472
473=item "my" variable %s masks earlier declaration in same scope
474
475(S) A lexical variable has been redeclared in the same scope, effectively
476eliminating all access to the previous instance. This is almost always
477a typographical error. Note that the earlier variable will still exist
478until the end of the scope or until all closure referents to it are
479destroyed.
480
481=item Allocation too large: %lx
482
483(X) You can't allocate more than 64K on an MSDOS machine.
484
485=item Allocation too large
486
487(F) You can't allocate more than 2^31+"small amount" bytes.
488
489=item Attempt to free non-existent shared string
490
491(P) Perl maintains a reference counted internal table of strings to
492optimize the storage and access of hash keys and other strings. This
493indicates someone tried to decrement the reference count of a string
494that can no longer be found in the table.
495
496=item Attempt to use reference as lvalue in substr
497
498(W) You supplied a reference as the first argument to substr() used
499as an lvalue, which is pretty strange. Perhaps you forgot to
500dereference it first. See L<perlfunc/substr>.
501
502=item Unsupported function fork
503
504(F) Your version of executable does not support forking.
505
506Note that under some systems, like OS/2, there may be different flavors of
507Perl executables, some of which may support fork, some not. Try changing
508the name you call Perl by to C<perl_>, C<perl__>, and so on.
509
510=item Ill-formed logical name |%s| in prime_env_iter
511
512(W) A warning peculiar to VMS. A logical name was encountered when preparing
513to iterate over %ENV which violates the syntactic rules governing logical
514names. Since it cannot be translated normally, it is skipped, and will not
515appear in %ENV. This may be a benign occurrence, as some software packages
516might directly modify logical name tables and introduce non-standard names,
517or it may indicate that a logical name table has been corrupted.
518
519=item Integer overflow in hex number
520
521(S) The literal hex number you have specified is too big for your
522architecture. On a 32-bit architecture the largest hex literal is
5230xFFFFFFFF.
524
525=item Integer overflow in octal number
526
527(S) The literal octal number you have specified is too big for your
528architecture. On a 32-bit architecture the largest octal literal is
529037777777777.
530
531=item Null picture in formline
532
533(F) The first argument to formline must be a valid format picture
534specification. It was found to be empty, which probably means you
535supplied it an uninitialized value. See L<perlform>.
536
537=item Offset outside string
538
539(F) You tried to do a read/write/send/recv operation with an offset
540pointing outside the buffer. This is difficult to imagine.
541The sole exception to this is that C<sysread()>ing past the buffer
542will extend the buffer and zero pad the new area.
543
544=item Out of memory!
545
546(X|F) The malloc() function returned 0, indicating there was insufficient
547remaining memory (or virtual memory) to satisfy the request.
548
549The request was judged to be small, so the possibility to trap it
550depends on the way Perl was compiled. By default it is not trappable.
551However, if compiled for this, Perl may use the contents of C<$^M> as
552an emergency pool after die()ing with this message. In this case the
553error is trappable I<once>.
554
555=item Out of memory during request for %s
556
557(F) The malloc() function returned 0, indicating there was insufficient
558remaining memory (or virtual memory) to satisfy the request. However,
559the request was judged large enough (compile-time default is 64K), so
560a possibility to shut down by trapping this error is granted.
561
562=item Possible attempt to put comments in qw() list
563
564(W) You probably wrote something like this:
565
566 qw( a # a comment
567 b # another comment
568 ) ;
569
570when you should have written this:
571
572 qw( a
573 b
574 ) ;
575
576=item Possible attempt to separate words with commas
577
578(W) You probably wrote something like this:
579
580 qw( a, b, c );
581
582when you should have written this:
583
584 qw( a b c );
585
586=item untie attempted while %d inner references still exist
587
588(W) A copy of the object returned from C<tie> (or C<tied>) was still
589valid when C<untie> was called.
590
591=item Got an error from DosAllocMem:
592
593(P) An error peculiar to OS/2. Most probably you use an obsolete version
594of Perl, and should not happen anyway.
595
596=item Malformed PERLLIB_PREFIX
597
598(F) An error peculiar to OS/2. PERLLIB_PREFIX should be of the form
599
600 prefix1;prefix2
601
602or
603
604 prefix1 prefix2
605
606with non-empty prefix1 and prefix2. If C<prefix1> is indeed a prefix of
607a builtin library search path, prefix2 is substituted. The error may appear
608if components are not found, or are too long. See L<perlos2/"PERLLIB_PREFIX">.
609
610=item PERL_SH_DIR too long
611
612(F) An error peculiar to OS/2. PERL_SH_DIR is the directory to find the
613C<sh>-shell in. See L<perlos2/"PERL_SH_DIR">.
614
615=item Process terminated by SIG%s
616
617(W) This is a standard message issued by OS/2 applications, while *nix
618applications die in silence. It is considered a feature of the OS/2
619port. One can easily disable this by appropriate sighandlers, see
620L<perlipc/"Signals">. See L<perlos2/"Process terminated by SIGTERM/SIGINT">.
621
622=back
623
624=head1 BUGS
625
626If you find what you think is a bug, you might check the headers
627of recently posted articles
628in the comp.lang.perl.misc newsgroup. There may also be
629information at http://www.perl.com/perl/, the Perl Home Page.
630
631If you believe you have an unreported bug, please run the B<perlbug>
632program included with your release. Make sure you trim your bug
633down to a tiny but sufficient test case. Your bug report, along
634with the output of C<perl -V>, will be sent off to perlbug@perl.com
635to be analysed by the Perl porting team.
636
637=head1 SEE ALSO
638
639The F<Changes> file for exhaustive details on what changed.
640
641The F<INSTALL> file for how to build Perl. This file has been
642significantly updated for 5.004, so even veteran users should
643look through it.
644
645The F<README> file for general stuff.
646
647The F<Copying> file for copyright information.
648
649=head1 HISTORY
650
651Constructed by Tom Christiansen, grabbing material with permission
652from innumerable contributors, with kibitzing by more than a few Perl
653porters.
654
7a4c00b4 655Last update: Tue Dec 24 16:45:14 EST 1996