forked from schacon/perl
/
perl5004delta.pod
1612 lines (1125 loc) · 54.9 KB
/
perl5004delta.pod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=head1 NAME
perl5004delta - what's new for perl5.004
=head1 DESCRIPTION
This document describes differences between the 5.003 release (as
documented in I<Programming Perl>, second edition--the Camel Book) and
this one.
=head1 Supported Environments
Perl5.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 it
cannot be built there, for lack of a reasonable command interpreter.
=head1 Core Changes
Most importantly, many bugs were fixed, including several security
problems. See the F<Changes> file in the distribution for details.
=head2 List assignment to %ENV works
C<%ENV = ()> and C<%ENV = @list> now work as expected (except on VMS
where it generates a fatal error).
=head2 Change to "Can't locate Foo.pm in @INC" error
The error "Can't locate Foo.pm in @INC" now lists the contents of @INC
for easier debugging.
=head2 Compilation option: Binary compatibility with 5.003
There is a new Configure question that asks if you want to maintain
binary compatibility with Perl 5.003. If you choose binary
compatibility, you do not have to recompile your extensions, but you
might have symbol conflicts if you embed Perl in another application,
just as in the 5.003 release. By default, binary compatibility
is preserved at the expense of symbol table pollution.
=head2 $PERL5OPT environment variable
You may now put Perl options in the $PERL5OPT environment variable.
Unless Perl is running with taint checks, it will interpret this
variable as if its contents had appeared on a "#!perl" line at the
beginning of your script, except that hyphens are optional. PERL5OPT
may only be used to set the following switches: B<-[DIMUdmw]>.
=head2 Limitations on B<-M>, B<-m>, and B<-T> options
The C<-M> and C<-m> options are no longer allowed on the C<#!> line of
a script. If a script needs a module, it should invoke it with the
C<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 -w
will probably work for an executable script invoked as C<scriptname>,
while:
#!/usr/bin/perl -w -T
will probably fail under the same conditions. (Non-Unix systems will
probably not follow this rule.) But C<perl scriptname> is guaranteed
to fail, since then there is no chance of B<-T> being found on the
command line before it is found on the C<#!> line.
=head2 More precise warnings
If you removed the B<-w> option from your Perl 5.003 scripts because it
made Perl too verbose, we recommend that you try putting it back when
you upgrade to Perl 5.004. Each new perl version tends to remove some
undesirable warnings, while adding new warnings that may catch bugs in
your scripts.
=head2 Deprecated: Inherited C<AUTOLOAD> for non-methods
Before Perl 5.004, C<AUTOLOAD> functions were looked up as methods
(using the C<@ISA> hierarchy), even when the function to be autoloaded
was 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 using
the old behavior. So, as an interim step, Perl 5.004 issues an optional
warning when a non-method uses an inherited C<AUTOLOAD>.
The simple rule is: Inheritance will not work when autoloading
non-methods. The simple fix for old code is: In any module that used to
depend on inheriting C<AUTOLOAD> for non-methods from a base class named
C<BaseClass>, execute C<*AUTOLOAD = \&BaseClass::AUTOLOAD> during startup.
=head2 Previously deprecated %OVERLOAD is no longer usable
Using %OVERLOAD to define overloading was deprecated in 5.003.
Overloading is now defined using the overload pragma. %OVERLOAD is
still used internally but should not be used by Perl scripts. See
L<overload> for more details.
=head2 Subroutine arguments created only when they're modified
In Perl 5.004, nonexistent array and hash elements used as subroutine
parameters are brought into existence only if they are actually
assigned 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 if
they 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] does
not. 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 list
as returned by the C<getgroups()> C function (if there is one).
However, until this release, there has not been a way to call the
C<setgroups()> C function from Perl.
In Perl 5.004, assigning to C<$)> is exactly symmetrical with examining
it: 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 the
C<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 the
old (broken) way inside strings; but it generates this message as a
warning. 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 the
regex-related special variables. Perl 5.004 does localize them, as
the 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 close
The documentation for Perl 5.0 has always stated that C<$.> is I<not>
reset when an already-open file handle is reopened with no intervening
call to C<close>. Due to a bug, perl versions 5.000 through 5.003
I<did> reset C<$.> under that circumstance; Perl 5.004 does not.
=head2 C<wantarray> may return undef
The C<wantarray> operator returns true if a subroutine is expected to
return a list, and false otherwise. In Perl 5.004, C<wantarray> can
also return the undefined value if a subroutine's return value will
not be used at all, which allows subroutines to avoid a time-consuming
calculation of a return value if it isn't going to be used.
=head2 C<eval EXPR> determines value of EXPR in scalar context
Perl (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 in
a scalar context. Once parsed, it is executed as before, by providing
the context that the scope surrounding the eval provided. This change
makes the behavior Perl4 compatible, besides fixing bugs resulting from
the 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 checks
A bug in previous versions may have failed to detect some insecure
conditions when taint checks are turned on. (Taint checks are used
in setuid or setgid scripts, or when explicitly turned on with the
C<-T> invocation option.) Although it's unlikely, this may cause a
previously-working script to now fail -- which should be construed
as a blessing, since that indicates a potentially-serious security
hole 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 made
safe. This restriction will be lifted in a future version of Perl
when globbing is implemented without the use of an external program.
=item No spawning if tainted $CDPATH, $ENV, $BASH_ENV
These environment variables may alter the behavior of spawned programs
(especially shells) in ways that subvert security. So now they are
treated as dangerous, in the manner of $IFS and $PATH.
=item No spawning if tainted $TERM doesn't look like a terminal name
Some termcap libraries do unsafe things with $TERM. However, it would be
unnecessarily harsh to treat all $TERM values as unsafe, since only shell
metacharacters can cause trouble in $TERM. So a tainted $TERM is
considered to be safe if it contains only alphanumerics, underscores,
dashes, and colons, and unsafe if it contains other characters (including
whitespace).
=back
=head2 New Opcode module and revised Safe module
A new Opcode module supports the creation, manipulation and
application of opcode masks. The revised Safe module has a new API
and is implemented using the new Opcode module. Please read the new
Opcode and Safe documentation.
=head2 Embedding improvements
In older versions of Perl it was not possible to create more than one
Perl interpreter instance inside a single process without leaking like a
sieve and/or crashing. The bugs that caused this behavior have all been
fixed. However, you still must take care when embedding Perl in a C
program. See the updated perlembed manpage for tips on how to manage
your interpreters.
=head2 Internal change: FileHandle class based on IO::* classes
File handles are now stored internally as type IO::Handle. The
FileHandle module is still supported for backwards compatibility, but
it is now merely a front end to the IO::* modules -- specifically,
IO::Handle, IO::Seekable, and IO::File. We suggest, but do not
require, that you use the IO::* modules in new code.
In harmony with this change, C<*GLOB{FILEHANDLE}> is now just a
backward-compatible synonym for C<*GLOB{IO}>.
=head2 Internal change: PerlIO abstraction interface
It is now possible to build Perl with AT&T's sfio IO package
instead of stdio. See L<perlapio> for more details, and
the 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 the
referenced subroutine, with the given parameters (if any).
This new syntax follows the pattern of S<C<< $hashref->{FOO} >>> and
S<C<< $aryref->[$foo] >>>: You may now write S<C<&$subref($foo)>> as
S<C<< $subref->($foo) >>>. All these arrow terms may be chained;
thus, S<C<< &{$table->{FOO}}($bar) >>> may now be written
S<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 if
there is no current package (due to a C<package;> directive). Like
C<__FILE__> and C<__LINE__>, C<__PACKAGE__> does I<not> interpolate
into strings.
=back
=head2 New and changed builtin variables
=over 4
=item $^E
Extended error message on some platforms. (Also known as
$EXTENDED_OS_ERROR if you C<use English>).
=item $^H
The current set of syntax checks enabled by C<use strict>. See the
documentation of C<strict> for more details. Not actually new, but
newly documented.
Because it is intended for internal use by Perl core components,
there is no C<use English> long name for this variable.
=item $^M
By default, running out of memory it is not trappable. However, if
compiled for this, Perl may use the contents of C<$^M> as an emergency
pool after die()ing with this message. Suppose that your Perl were
compiled 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 slices
This now works. (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
=item flock
is now supported on more platforms, prefers fcntl to lockf when
emulating, and always flushes before (un)locking.
=item printf and sprintf
Perl now implements these functions itself; it doesn't use the C
library function sprintf() any more, except for floating-point
numbers, and even then only known flags are allowed. As a result, it
is now possible to know which conversions and flags will work, and
what 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 type
Also, where a number would appear in the flags, an asterisk ("*") may
be used instead, in which case Perl uses the next item in the
parameter list as the given number (that is, as the field width or
precision). If a field width obtained through "*" is negative, it has
the same effect as the '-' flag: left-justification.
See L<perlfunc/sprintf> for a complete list of conversion and flags.
=item keys as an lvalue
As an lvalue, C<keys> allows you to increase the number of hash buckets
allocated for the given hash. This can gain you a measure of efficiency if
you know the hash is going to get big. (This is similar to pre-extending
an 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. These
buckets 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 using
C<keys> in this way (but you needn't worry about doing this by accident,
as trying has no effect).
=item my() in Control Structures
You can now use my() (with or without the parentheses) in the control
expressions 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
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 of
the loop, but not beyond it.
Note that you still cannot use my() on global punctuation variables
such as $_ and the like.
=item pack() and unpack()
A new format 'w' represents a BER compressed integer (as defined in
ASN.1). Its format is a sequence of one or more bytes, each of which
provides seven bits of the total value, with the most significant
first. Bit eight of each byte is set, except for the last byte, in
which bit eight is clear.
If 'p' or 'P' are given undef as values, they now generate a NULL
pointer.
Both pack() and unpack() now fail when their templates contain invalid
types. (Invalid types used to be ignored.)
=item sysseek()
The new sysseek() operator is a variant of seek() that sets and gets the
file's system read/write position, using the lseek(2) system call. It is
the only reliable way to seek before using sysread() or syswrite(). Its
return value is the new position, or the undefined value on failure.
=item use VERSION
If the first argument to C<use> is a number, it is treated as a version
number instead of a module name. If the version of the Perl interpreter
is less than VERSION, then an error message is printed and Perl exits
immediately. Because C<use> occurs at compile time, this check happens
immediately during the compilation process, unlike C<require VERSION>,
which waits until runtime for the check. This is often useful if you
need to check the current Perl version before C<use>ing library modules
which 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 LIST
If the VERSION argument is present between Module and LIST, then the
C<use> will call the VERSION method in class Module with the given
version as an argument. The default VERSION method, inherited from
the UNIVERSAL class, croaks if the given version is larger than the
value of the variable $Module::VERSION. (Note that there is not a
comma after VERSION!)
This version-checking mechanism is similar to the one currently used
in the Exporter module, but it is faster and can be used with modules
that don't use the Exporter. It is the recommended method for new
code.
=item prototype(FUNCTION)
Returns the prototype of a function as a string (or C<undef> if the
function has no prototype). FUNCTION is a reference to or the name of the
function whose prototype you want to retrieve.
(Not actually new; just never documented before.)
=item srand
The 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 called
C<srand>, it calls C<srand> with the default seed. You should still call
C<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 Default
Functions documented in the Camel to default to $_ now in
fact do, and all those that do are so documented in L<perlfunc>.
=item C<m//gc> does not reset search position on failure
The C<m//g> match iteration construct has always reset its target
string'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 failure
starts again at the beginning of the string. With Perl 5.004, this
reset may be disabled by adding the "c" (for "continue") modifier,
i.e. C<m//gc>. This feature, in conjunction with the C<\G> zero-width
assertion, 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 unescaped
whitespace. However, before Perl 5.004, whitespace had the effect of
escaping 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 now
Prior to the 5.004 release, nested anonymous functions didn't work
right. They do now.
=item formats work right on changing lexicals
Just like anonymous functions that contain lexical variables
that change (like a lexical index variable for a C<foreach> loop),
formats now work properly. For example, this silently failed
before (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 a
subroutine:
my $i;
sub foo {
foreach $i ( 1 .. 10 ) {
write;
}
}
foo;
format =
my i is @#
$i
.
=back
=head2 New builtin methods
The C<UNIVERSAL> package automatically contains the following methods that
are 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. This
allows 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 then
I<undef> is returned.
=item VERSION( [NEED] )
C<VERSION> returns the version number of the class (package). If the
NEED argument is given then it will check that the current version (as
defined by the $VERSION variable in the given package) not less than
NEED; it will die if this is not the case. This method is normally
called as a class method. This method is called automatically by the
C<VERSION> form of C<use>.
use A 1.2 qw(some imported subs);
# implies:
A->VERSION(1.2);
=back
B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
C<isa> uses a very similar method and caching strategy. This may cause
strange 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 methods
available to your program. This is necessary only if you wish to
have C<isa> available as a plain subroutine in the current package.
=head2 TIEHANDLE now supported
See L<perltie> for other kinds of tie()s.
=over 4
=item TIEHANDLE classname, LIST
This is the constructor for the class. That means it is expected to
return an object of some sort. The reference can be used to
hold some internal information.
sub TIEHANDLE {
print "<shout>\n";
my $i;
return bless \$i, shift;
}
=item PRINT this, LIST
This method will be triggered every time the tied handle is printed to.
Beyond its self reference it also expects the list that was passed to
the print function.
sub PRINT {
$r = shift;
$$r++;
return print join( $, => map {uc} @_), $\;
}
=item PRINTF this, LIST
This method will be triggered every time the tied handle is printed to
with the C<printf()> function.
Beyond its self reference it also expects the format and list that was
passed to the printf function.
sub PRINTF {
shift;
my $fmt = shift;
print sprintf($fmt, @_)."\n";
}
=item READ this LIST
This 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 this
This method will be called when the handle is read from. The method
should return undef when there is no more data.
sub READLINE {
$r = shift;
return "PRINT called $$r times\n"
}
=item GETC this
This method will be called when the C<getc> function is called.
sub GETC { print "Don't GETC, Get Perl"; return "a"; }
=item DESTROY this
As with the other types of ties, this method will be called when the
tied handle is about to be destroyed. This is useful for debugging and
possibly for cleaning up.
sub DESTROY {
print "</shout>\n";
}
=back
=head2 Malloc enhancements
If perl is compiled with the malloc included with the perl distribution
(that is, if C<perl -V:d_mymalloc> is 'define') then you can print
memory statistics at runtime by running Perl thusly:
env PERL_DEBUG_MSTATS=2 perl your_script_here
The value of 2 means to print statistics after compilation and on
exit; with a value of 1, the statistics are printed only on exit.
(If you want the statistics at an arbitrary time, you'll need to
install the optional module Devel::Peek.)
Three new compilation flags are recognized by malloc.c. (They have no
effect if perl is compiled with system malloc().)
=over 4
=item -DPERL_EMERGENCY_SBRK
If this macro is defined, running out of memory need not be a fatal
error: a memory pool can allocated by assigning to the special
variable C<$^M>. See L<"$^M">.
=item -DPACK_MALLOC
Perl memory allocation is by bucket with sizes close to powers of two.
Because of these malloc overhead may be big, especially for data of
size exactly a power of two. If C<PACK_MALLOC> is defined, perl uses
a slightly different algorithm for small allocations (up to 64 bytes
long), which makes it possible to have overhead down to 1 byte for
allocations which are powers of two (and appear quite often).
Expected memory savings (with 8-byte alignment in C<alignbytes>) is
about 20% for typical Perl usage. Expected slowdown due to additional
malloc overhead is in fractions of a percent (hard to measure, because
of the effect of saved memory on speed).
=item -DTWO_POT_OPTIMIZE
Similarly to C<PACK_MALLOC>, this macro improves allocations of data
with size close to a power of two; but this works for big allocations
(starting with 16K by default). Such allocations are typical for big
hashes and special-purpose scripts, especially image processing.
On recent systems, the fact that perl requires 2M from system for 1M
allocation will not affect speed of execution, since the tail of such
a chunk is not going to be touched (and thus will not require real
memory). However, it may result in a premature out-of-memory error.
So if you will be manipulating very large blocks with sizes close to
powers of two, it would be wise to define this macro.
Expected saving of memory is 0-100% (100% in applications which
require most memory in such 2**n chunks); expected slowdown is
negligible.
=back
=head2 Miscellaneous efficiency enhancements
Functions that have an empty prototype and that do nothing but return
a fixed value are now inlined (e.g. C<sub PI () { 3.14159 }>).
Each unique hash key is only allocated once, no matter how many hashes
have an entry with that key. So even if you have 100 copies of the
same hash, the hash keys never have to be reallocated.
=head1 Support for More Operating Systems
Support for the following operating systems is new in Perl 5.004.
=head2 Win32
Perl 5.004 now includes support for building a "native" perl under
Windows NT, using the Microsoft Visual C++ compiler (versions 2.0
and above) or the Borland C++ compiler (versions 5.02 and above).
The resulting perl can be used under Windows 95 (if it
is installed in the same directory locations as it got installed
in Windows NT). This port includes support for perl extension
building tools like L<MakeMaker> and L<h2xs>, so that many extensions
available on the Comprehensive Perl Archive Network (CPAN) can now be
readily built under Windows NT. See http://www.perl.com/ for more
information on CPAN and F<README.win32> in the perl distribution for more
details 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 run
many Unix programs under Windows NT by providing a mostly Unix-like
interface for compilation and execution. See F<README.cygwin32> in the
perl distribution for more details on this port and how to obtain the
Cygwin32 toolkit.
=head2 Plan 9
See F<README.plan9> in the perl distribution.
=head2 QNX
See F<README.qnx> in the perl distribution.
=head2 AmigaOS
See F<README.amigaos> in the perl distribution.
=head1 Pragmata
Six new pragmatic modules exist:
=over 4
=item use autouse MODULE => qw(sub1 sub2 sub3)
Defers C<require MODULE> until someone calls one of the specified
subroutines (which must be exported by MODULE). This pragma should be
used with caution, and only when necessary.
=item use blib
=item use blib 'dir'
Looks for MakeMaker-like I<'blib'> directory structure starting in
I<dir> (or current directory) and working back up to five levels of
parent directories.
Intended for use on command line with B<-M> option as a way of testing
arbitrary scripts against an uninstalled version of a package.
=item use constant NAME => VALUE
Provides a convenient interface for creating compile-time constants,
See L<perlsub/"Constant Functions">.
=item use locale
Tells the compiler to enable (or disable) the use of POSIX locales for
builtin operations.
When C<use locale> is in effect, the current LC_CTYPE locale is used
for regular expressions and case mapping; LC_COLLATE for string
ordering; and LC_NUMERIC for numeric formatting in printf and sprintf
(but B<not> in print). LC_NUMERIC is always used in write, since
lexical scoping of formats is problematic at best.
Each C<use locale> or C<no locale> affects statements to the end of
the enclosing BLOCK or, if not inside a BLOCK, to the end of the
current file. Locales can be switched and queried with
POSIX::setlocale().
See L<perllocale> for more information.
=item use ops
Disable unsafe opcodes, or any named opcodes, when compiling Perl code.
=item use vmsish
Enable VMS-specific language features. Currently, there are three
VMS-specific features available: 'status', which makes C<$?> and
C<system> return genuine VMS status values instead of emulating POSIX;
'exit', which makes C<exit> take a genuine VMS status value instead of
assuming that C<exit 1> is an error; and 'time', which makes all times
relative to the local time zone, in the VMS tradition.
=back
=head1 Modules
=head2 Required Updates
Though Perl 5.004 is compatible with almost all modules that work
with Perl 5.003, there are a few exceptions:
Module Required Version for Perl 5.004
------ -------------------------------
Filter Filter-1.12
LWP libwww-perl-5.08
Tk Tk400.202 (-w makes noise)
Also, the majordomo mailing list program, version 1.94.1, doesn't work
with Perl 5.004 (nor with perl 4), because it executes an invalid
regular expression. This bug is fixed in majordomo version 1.94.2.
=head2 Installation directories
The I<installperl> script now places the Perl source files for
extensions in the architecture-specific library directory, which is
where the shared libraries for extensions have always been. This
change is intended to allow administrators to keep the Perl 5.004
library directory unchanged from a previous version, without running
the risk of binary incompatibility between extensions' Perl source and
shared libraries.
=head2 Module information summary
Brand new modules, arranged by topic rather than strictly
alphabetically:
CGI.pm Web server interface ("Common Gateway Interface")
CGI/Apache.pm Support for Apache's Perl module
CGI/Carp.pm Log server errors with helpful context
CGI/Fast.pm Support for FastCGI (persistent server process)
CGI/Push.pm Support for server push
CGI/Switch.pm Simple interface for multiple server types
CPAN Interface to Comprehensive Perl Archive Network
CPAN::FirstTime Utility for creating CPAN configuration file
CPAN::Nox Runs CPAN while avoiding compiled extensions
IO.pm Top-level interface to IO::* classes
IO/File.pm IO::File extension Perl module
IO/Handle.pm IO::Handle extension Perl module
IO/Pipe.pm IO::Pipe extension Perl module
IO/Seekable.pm IO::Seekable extension Perl module
IO/Select.pm IO::Select extension Perl module
IO/Socket.pm IO::Socket extension Perl module
Opcode.pm Disable named opcodes when compiling Perl code
ExtUtils/Embed.pm Utilities for embedding Perl in C programs
ExtUtils/testlib.pm Fixes up @INC to use just-built extension
FindBin.pm Find path of currently executing program
Class/Struct.pm Declare struct-like datatypes as Perl classes
File/stat.pm By-name interface to Perl's builtin stat
Net/hostent.pm By-name interface to Perl's builtin gethost*
Net/netent.pm By-name interface to Perl's builtin getnet*
Net/protoent.pm By-name interface to Perl's builtin getproto*
Net/servent.pm By-name interface to Perl's builtin getserv*
Time/gmtime.pm By-name interface to Perl's builtin gmtime
Time/localtime.pm By-name interface to Perl's builtin localtime
Time/tm.pm Internal object for Time::{gm,local}time
User/grent.pm By-name interface to Perl's builtin getgr*
User/pwent.pm By-name interface to Perl's builtin getpw*
Tie/RefHash.pm Base class for tied hashes with references as keys
UNIVERSAL.pm Base class for *ALL* classes
=head2 Fcntl
New constants in the existing Fcntl modules are now supported,
provided that your operating system happens to support them:
F_GETOWN F_SETOWN
O_ASYNC O_DEFER O_DSYNC O_FSYNC O_SYNC
O_EXLOCK O_SHLOCK
These constants are intended for use with the Perl operators sysopen()
and fcntl() and the basic database modules like SDBM_File. For the
exact meaning of these and other Fcntl constants please refer to your
operating system's documentation for fcntl() and open().
In addition, the Fcntl module now provides these constants for use
with the Perl operator flock():
LOCK_SH LOCK_EX LOCK_NB LOCK_UN
These constants are defined in all environments (because where there is
no flock() system call, Perl emulates it). However, for historical
reasons, these constants are not exported unless they are explicitly
requested with the ":flock" tag (e.g. C<use Fcntl ':flock'>).
=head2 IO
The IO module provides a simple mechanism to load all the IO modules at one
go. Currently this includes:
IO::Handle
IO::Seekable
IO::File
IO::Pipe
IO::Socket
For more information on any of these modules, please see its
respective documentation.
=head2 Math::Complex
The Math::Complex module has been totally rewritten, and now supports
more operations. These are overloaded:
+ - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
And these functions are now exported:
pi i Re Im arg
log10 logn ln cbrt root
tan
csc sec cot
asin acos atan
acsc asec acot
sinh cosh tanh
csch sech coth
asinh acosh atanh
acsch asech acoth
cplx cplxe
=head2 Math::Trig
This new module provides a simpler interface to parts of Math::Complex for
those who need trigonometric functions only for real numbers.
=head2 DB_File
There have been quite a few changes made to DB_File. Here are a few of
the highlights:
=over 4
=item *
Fixed a handful of bugs.
=item *
By public demand, added support for the standard hash function exists().
=item *
Made it compatible with Berkeley DB 1.86.
=item *