This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
gv_fetchpvn and gv_fetchpvn_flags are identical
[perl5.git] / pod / perldeprecation.pod
1 =head1 NAME
2
3 perldeprecation - list Perl deprecations
4
5 =head1 DESCRIPTION
6
7 The purpose of this document is to document what has been deprecated
8 in Perl, and by which version the deprecated feature will disappear,
9 or, for already removed features, when it was removed.
10
11 This document will try to discuss what alternatives for the deprecated
12 features are available.
13
14 The deprecated features will be grouped by the version of Perl in
15 which they will be removed.
16
17 =head2 Perl 5.34
18
19 There are no deprecations or fatalizations scheduled for Perl 5.34.
20
21 =head2 Perl 5.32
22
23 =head3 Constants from lexical variables potentially modified elsewhere
24
25 You wrote something like
26
27     my $var;
28     $sub = sub () { $var };
29
30 but $var is referenced elsewhere and could be modified after the C<sub>
31 expression is evaluated.  Either it is explicitly modified elsewhere
32 (C<$var = 3>) or it is passed to a subroutine or to an operator like
33 C<printf> or C<map>, which may or may not modify the variable.
34
35 Traditionally, Perl has captured the value of the variable at that
36 point and turned the subroutine into a constant eligible for inlining.
37 In those cases where the variable can be modified elsewhere, this
38 breaks the behavior of closures, in which the subroutine captures
39 the variable itself, rather than its value, so future changes to the
40 variable are reflected in the subroutine's return value.
41
42 If you intended for the subroutine to be eligible for inlining, then
43 make sure the variable is not referenced elsewhere, possibly by
44 copying it:
45
46     my $var2 = $var;
47     $sub = sub () { $var2 };
48
49 If you do want this subroutine to be a closure that reflects future
50 changes to the variable that it closes over, add an explicit C<return>:
51
52     my $var;
53     $sub = sub () { return $var };
54
55 This usage was deprecated and as of Perl 5.32 is no longer allowed.
56
57 =head3 Use of strings with code points over 0xFF as arguments to C<vec>
58
59 C<vec> views its string argument as a sequence of bits.  A string
60 containing a code point over 0xFF is nonsensical.  This usage is
61 deprecated in Perl 5.28, and was removed in Perl 5.32.
62
63 =head3 Use of code points over 0xFF in string bitwise operators
64
65 The string bitwise operators, C<&>, C<|>, C<^>, and C<~>, treat their
66 operands as strings of bytes. As such, values above 0xFF are
67 nonsensical. Some instances of these have been deprecated since Perl
68 5.24, and were made fatal in 5.28, but it turns out that in cases where
69 the wide characters did not affect the end result, no deprecation
70 notice was raised, and so remain legal.  Now, all occurrences either are
71 fatal or raise a deprecation warning, so that the remaining legal
72 occurrences became fatal in 5.32.
73
74 An example of this is
75
76  "" & "\x{100}"
77
78 The wide character is not used in the C<&> operation because the left
79 operand is shorter.  This now throws an exception.
80
81 =head3 hostname() doesn't accept any arguments
82
83 The function C<hostname()> in the L<Sys::Hostname> module has always
84 been documented to be called with no arguments.  Historically it has not
85 enforced this, and has actually accepted and ignored any arguments.  As a
86 result, some users have got the mistaken impression that an argument does
87 something useful.  To avoid these bugs, the function is being made strict.
88 Passing arguments was deprecated in Perl 5.28 and became fatal in Perl 5.32.
89
90 =head3 Unescaped left braces in regular expressions
91
92 The simple rule to remember, if you want to match a literal C<{>
93 character (U+007B C<LEFT CURLY BRACKET>) in a regular expression
94 pattern, is to escape each literal instance of it in some way.
95 Generally easiest is to precede it with a backslash, like C<\{>
96 or enclose it in square brackets (C<[{]>).  If the pattern
97 delimiters are also braces, any matching right brace (C<}>) should
98 also be escaped to avoid confusing the parser, for example,
99
100  qr{abc\{def\}ghi}
101
102 Forcing literal C<{> characters to be escaped will enable the Perl
103 language to be extended in various ways in future releases.  To avoid
104 needlessly breaking existing code, the restriction is not enforced in
105 contexts where there are unlikely to ever be extensions that could
106 conflict with the use there of C<{> as a literal.  A non-deprecation
107 warning that the left brace is being taken literally is raised in
108 contexts where there could be confusion about it.
109
110 Literal uses of C<{> were deprecated in Perl 5.20, and some uses of it
111 started to give deprecation warnings since. These cases were made fatal
112 in Perl 5.26. Due to an oversight, not all cases of a use of a literal
113 C<{> got a deprecation warning.  Some cases started warning in Perl 5.26,
114 and were made fatal in Perl 5.30.  Other cases started in Perl 5.28,
115 and were made fatal in 5.32.
116
117 =head3 In XS code, use of various macros dealing with UTF-8.
118
119 The macros below now require an extra parameter than in versions prior
120 to Perl 5.32.  The final parameter in each one is a pointer into the
121 string supplied by the first parameter beyond which the input will not
122 be read.  This prevents potential reading beyond the end of the buffer.
123 C<isALPHANUMERIC_utf8>,
124 C<isASCII_utf8>,
125 C<isBLANK_utf8>,
126 C<isCNTRL_utf8>,
127 C<isDIGIT_utf8>,
128 C<isIDFIRST_utf8>,
129 C<isPSXSPC_utf8>,
130 C<isSPACE_utf8>,
131 C<isVERTWS_utf8>,
132 C<isWORDCHAR_utf8>,
133 C<isXDIGIT_utf8>,
134 C<isALPHANUMERIC_LC_utf8>,
135 C<isALPHA_LC_utf8>,
136 C<isASCII_LC_utf8>,
137 C<isBLANK_LC_utf8>,
138 C<isCNTRL_LC_utf8>,
139 C<isDIGIT_LC_utf8>,
140 C<isGRAPH_LC_utf8>,
141 C<isIDCONT_LC_utf8>,
142 C<isIDFIRST_LC_utf8>,
143 C<isLOWER_LC_utf8>,
144 C<isPRINT_LC_utf8>,
145 C<isPSXSPC_LC_utf8>,
146 C<isPUNCT_LC_utf8>,
147 C<isSPACE_LC_utf8>,
148 C<isUPPER_LC_utf8>,
149 C<isWORDCHAR_LC_utf8>,
150 C<isXDIGIT_LC_utf8>,
151 C<toFOLD_utf8>,
152 C<toLOWER_utf8>,
153 C<toTITLE_utf8>,
154 and
155 C<toUPPER_utf8>.
156
157 Since Perl 5.26, this functionality with the extra parameter has been
158 available by using a corresponding macro to each one of these, and whose
159 name is formed by appending C<_safe> to the base name.  There is no
160 change to the functionality of those.  For example, C<isDIGIT_utf8_safe>
161 corresponds to C<isDIGIT_utf8>, and both now behave identically.  All
162 are documented in L<perlapi/Character case changing> and
163 L<perlapi/Character classification>.
164
165 This change was originally scheduled for 5.30, but was delayed until
166 5.32.
167
168 =head3 C<< File::Glob::glob() >> was removed
169
170 C<< File::Glob >> has a function called C<< glob >>, which just calls
171 C<< bsd_glob >>.
172
173 C<< File::Glob::glob() >> was deprecated in Perl 5.8. A deprecation
174 message was issued from Perl 5.26 onwards, and the function has now
175 disappeared in Perl 5.30.
176
177 Code using C<< File::Glob::glob() >> should call
178 C<< File::Glob::bsd_glob() >> instead.
179
180 =head2 Perl 5.30
181
182 =head3 C<< $* >> is no longer supported
183
184 Before Perl 5.10, setting C<< $* >> to a true value globally enabled
185 multi-line matching within a string. This relique from the past lost
186 its special meaning in 5.10. Use of this variable will be a fatal error
187 in Perl 5.30, freeing the variable up for a future special meaning.
188
189 To enable multiline matching one should use the C<< /m >> regexp
190 modifier (possibly in combination with C<< /s >>). This can be set
191 on a per match bases, or can be enabled per lexical scope (including
192 a whole file) with C<< use re '/m' >>.
193
194 =head3 C<< $# >> is no longer supported
195
196 This variable used to have a special meaning -- it could be used
197 to control how numbers were formatted when printed. This seldom
198 used functionality was removed in Perl 5.10. In order to free up
199 the variable for a future special meaning, its use will be a fatal
200 error in Perl 5.30.
201
202 To specify how numbers are formatted when printed, one is advised
203 to use C<< printf >> or C<< sprintf >> instead.
204
205 =head3 Assigning non-zero to C<< $[ >> is fatal
206
207 This variable (and the corresponding C<array_base> feature and
208 L<arybase> module) allowed changing the base for array and string
209 indexing operations.
210
211 Setting this to a non-zero value has been deprecated since Perl 5.12 and
212 throws a fatal error as of Perl 5.30.
213
214 =head3 C<< File::Glob::glob() >> will disappear
215
216 C<< File::Glob >> has a function called C<< glob >>, which just calls
217 C<< bsd_glob >>. However, its prototype is different from the prototype
218 of C<< CORE::glob >>, and hence, C<< File::Glob::glob >> should not
219 be used.
220
221 C<< File::Glob::glob() >> was deprecated in Perl 5.8. A deprecation
222 message was issued from Perl 5.26 onwards, and the function will
223 disappear in Perl 5.30.
224
225 Code using C<< File::Glob::glob() >> should call
226 C<< File::Glob::bsd_glob() >> instead.
227
228 =head3 Unescaped left braces in regular expressions (for 5.30)
229
230 See L</Unescaped left braces in regular expressions> above.
231
232 =head3 Unqualified C<dump()>
233
234 Use of C<dump()> instead of C<CORE::dump()> was deprecated in Perl 5.8,
235 and an unqualified C<dump()> will no longer be available in Perl 5.30.
236
237 See L<perlfunc/dump>.
238
239
240 =head3 Using my() in false conditional.
241
242 There has been a long-standing bug in Perl that causes a lexical variable
243 not to be cleared at scope exit when its declaration includes a false
244 conditional.  Some people have exploited this bug to achieve a kind of
245 static variable.  To allow us to fix this bug, people should not be
246 relying on this behavior.
247
248 Instead, it's recommended one uses C<state> variables to achieve the
249 same effect:
250
251     use 5.10.0;
252     sub count {state $counter; return ++ $counter}
253     say count ();    # Prints 1
254     say count ();    # Prints 2
255
256 C<state> variables were introduced in Perl 5.10.
257
258 Alternatively, you can achieve a similar static effect by
259 declaring the variable in a separate block outside the function, e.g.,
260
261     sub f { my $x if 0; return $x++ }
262
263 becomes
264
265     { my $x; sub f { return $x++ } }
266
267 The use of C<my()> in a false conditional has been deprecated in
268 Perl 5.10, and became a fatal error in Perl 5.30.
269
270
271 =head3 Reading/writing bytes from/to :utf8 handles.
272
273 The sysread(), recv(), syswrite() and send() operators are
274 deprecated on handles that have the C<:utf8> layer, either explicitly, or
275 implicitly, eg., with the C<:encoding(UTF-16LE)> layer.
276
277 Both sysread() and recv() currently use only the C<:utf8> flag for the stream,
278 ignoring the actual layers.  Since sysread() and recv() do no UTF-8
279 validation they can end up creating invalidly encoded scalars.
280
281 Similarly, syswrite() and send() use only the C<:utf8> flag, otherwise ignoring
282 any layers.  If the flag is set, both write the value UTF-8 encoded, even if
283 the layer is some different encoding, such as the example above.
284
285 Ideally, all of these operators would completely ignore the C<:utf8> state,
286 working only with bytes, but this would result in silently breaking existing
287 code.  To avoid this a future version of perl will throw an exception when
288 any of sysread(), recv(), syswrite() or send() are called on handle with the
289 C<:utf8> layer.
290
291 In Perl 5.30, it will no longer be possible to use sysread(), recv(),
292 syswrite() or send() to read or send bytes from/to :utf8 handles.
293
294
295 =head3 Use of unassigned code point or non-standalone grapheme for a delimiter.
296
297 A grapheme is what appears to a native-speaker of a language to be a
298 character.  In Unicode (and hence Perl) a grapheme may actually be
299 several adjacent characters that together form a complete grapheme.  For
300 example, there can be a base character, like "R" and an accent, like a
301 circumflex "^", that appear to be a single character when displayed,
302 with the circumflex hovering over the "R".
303
304 As of Perl 5.30, use of delimiters which are non-standalone graphemes is
305 fatal, in order to move the language to be able to accept
306 multi-character graphemes as delimiters.
307
308 Also, as of Perl 5.30, delimiters which are unassigned code points
309 but that may someday become assigned are prohibited.  Otherwise, code
310 that works today would fail to compile if the currently unassigned
311 delimiter ends up being something that isn't a stand-alone grapheme.
312 Because Unicode is never going to assign L<non-character code
313 points|perlunicode/Noncharacter code points>, nor L<code points that are
314 above the legal Unicode maximum|perlunicode/Beyond Unicode code
315 points>, those can be delimiters.
316
317 =head2 Perl 5.28
318
319 =head3 Attributes C<< :locked >> and C<< :unique >>
320
321 The attributes C<< :locked >> (on code references) and C<< :unique >>
322 (on array, hash and scalar references) have had no effect since 
323 Perl 5.005 and Perl 5.8.8 respectively. Their use has been deprecated
324 since.
325
326 As of Perl 5.28, these attributes are syntax errors. Since the
327 attributes do not do anything, removing them from your code fixes
328 the syntax error; and removing them will not influence the behaviour
329 of your code.
330
331
332 =head3 Bare here-document terminators
333
334 Perl has allowed you to use a bare here-document terminator to have the
335 here-document end at the first empty line. This practise was deprecated
336 in Perl 5.000; as of Perl 5.28, using a bare here-document terminator
337 throws a fatal error.
338
339 You are encouraged to use the explicitly quoted form if you wish to
340 use an empty line as the terminator of the here-document:
341
342   print <<"";
343     Print this line.
344
345   # Previous blank line ends the here-document.
346
347
348 =head3 Setting $/ to a reference to a non-positive integer
349
350 You assigned a reference to a scalar to C<$/> where the
351 referenced item is not a positive integer.  In older perls this B<appeared>
352 to work the same as setting it to C<undef> but was in fact internally
353 different, less efficient and with very bad luck could have resulted in
354 your file being split by a stringified form of the reference.
355
356 In Perl 5.20.0 this was changed so that it would be B<exactly> the same as
357 setting C<$/> to undef, with the exception that this warning would be
358 thrown.
359
360 As of Perl 5.28, setting C<$/> to a reference of a non-positive
361 integer throws a fatal error.
362
363 You are recommended to change your code to set C<$/> to C<undef> explicitly
364 if you wish to slurp the file.
365
366
367 =head3 Limit on the value of Unicode code points.
368
369 Unicode only allows code points up to 0x10FFFF, but Perl allows
370 much larger ones. Up till Perl 5.28, it was allowed to use code
371 points exceeding the maximum value of an integer (C<IV_MAX>).
372 However, that did break the perl interpreter in some constructs,
373 including causing it to hang in a few cases.  The known problem
374 areas were in C<tr///>, regular expression pattern matching using
375 quantifiers, as quote delimiters in C<qI<X>...I<X>> (where I<X> is
376 the C<chr()> of a large code point), and as the upper limits in
377 loops.
378
379 The use of out of range code points was deprecated in Perl 5.24; as of
380 Perl 5.28 using a code point exceeding C<IV_MAX> throws a fatal error.
381
382 If your code is to run on various platforms, keep in mind that the upper
383 limit depends on the platform. It is much larger on 64-bit word sizes
384 than 32-bit ones. For 32-bit integers, C<IV_MAX> equals C<0x7FFFFFFF>,
385 for 64-bit integers, C<IV_MAX> equals C<0x7FFFFFFFFFFFFFFF>.
386
387
388 =head3 Use of comma-less variable list in formats.
389
390 It was allowed to use a list of variables in a format, without
391 separating them with commas. This usage has been deprecated
392 for a long time, and as of Perl 5.28, this throws a fatal error.
393
394 =head3 Use of C<\N{}>
395
396 Use of C<\N{}> with nothing between the braces was deprecated in
397 Perl 5.24, and throws a fatal error as of Perl 5.28.
398
399 Since such a construct is equivalent to using an empty string,
400 you are recommended to remove such C<\N{}> constructs.
401
402 =head3 Using the same symbol to open a filehandle and a dirhandle
403
404 It used to be legal to use C<open()> to associate both a
405 filehandle and a dirhandle to the same symbol (glob or scalar).
406 This idiom is likely to be confusing, and it was deprecated in
407 Perl 5.10.
408
409 Using the same symbol to C<open()> a filehandle and a dirhandle
410 throws a fatal error as of Perl 5.28.
411
412 You should be using two different symbols instead.
413
414 =head3 ${^ENCODING} is no longer supported.
415
416 The special variable C<${^ENCODING}> was used to implement
417 the C<encoding> pragma. Setting this variable to anything other
418 than C<undef> was deprecated in Perl 5.22. Full deprecation
419 of the variable happened in Perl 5.25.3.
420
421 Setting this variable to anything other than an undefined value
422 throws a fatal error as of Perl 5.28.
423
424
425 =head3 C<< B::OP::terse >>
426
427 This method, which just calls C<< B::Concise::b_terse >>, has been
428 deprecated, and disappeared in Perl 5.28. Please use 
429 C<< B::Concise >> instead.
430
431
432
433 =head3 Use of inherited AUTOLOAD for non-method %s::%s() is no longer allowed
434
435 As an (ahem) accidental feature, C<AUTOLOAD> subroutines were looked
436 up as methods (using the C<@ISA> hierarchy) even when the subroutines
437 to be autoloaded were called as plain functions (e.g. C<Foo::bar()>),
438 not as methods (e.g. C<< Foo->bar() >> or C<< $obj->bar() >>).
439
440 This bug was deprecated in Perl 5.004, has been rectified in Perl 5.28
441 by using method lookup only for methods' C<AUTOLOAD>s.
442
443 The simple rule is:  Inheritance will not work when autoloading
444 non-methods.  The simple fix for old code is:  In any module that used
445 to depend on inheriting C<AUTOLOAD> for non-methods from a base class
446 named C<BaseClass>, execute C<*AUTOLOAD = \&BaseClass::AUTOLOAD> during
447 startup.
448
449 In code that currently says C<use AutoLoader; @ISA = qw(AutoLoader);>
450 you should remove AutoLoader from @ISA and change C<use AutoLoader;> to
451 C<use AutoLoader 'AUTOLOAD';>.
452
453
454 =head3 Use of code points over 0xFF in string bitwise operators
455
456 The string bitwise operators, C<&>, C<|>, C<^>, and C<~>, treat
457 their operands as strings of bytes. As such, values above 0xFF 
458 are nonsensical. Using such code points with these operators
459 was deprecated in Perl 5.24, and is fatal as of Perl 5.28.
460
461 =head3 In XS code, use of C<to_utf8_case()>
462
463 This function has been removed as of Perl 5.28; instead convert to call
464 the appropriate one of:
465 L<C<toFOLD_utf8_safe>|perlapi/toFOLD_utf8_safe>.
466 L<C<toLOWER_utf8_safe>|perlapi/toLOWER_utf8_safe>,
467 L<C<toTITLE_utf8_safe>|perlapi/toTITLE_utf8_safe>,
468 or
469 L<C<toUPPER_utf8_safe>|perlapi/toUPPER_utf8_safe>.
470
471 =head2 Perl 5.26
472
473 =head3 C<< --libpods >> in C<< Pod::Html >>
474
475 Since Perl 5.18, the option C<< --libpods >> has been deprecated, and
476 using this option did not do anything other than producing a warning.
477
478 The C<< --libpods >> option is no longer recognized as of Perl 5.26.
479
480
481 =head3 The utilities C<< c2ph >> and C<< pstruct >>
482
483 These old, perl3-era utilities have been deprecated in favour of
484 C<< h2xs >> for a long time. As of Perl 5.26, they have been removed.
485
486
487 =head3 Trapping C<< $SIG {__DIE__} >> other than during program exit.
488
489 The C<$SIG{__DIE__}> hook is called even inside an C<eval()>. It was
490 never intended to happen this way, but an implementation glitch made
491 this possible. This used to be deprecated, as it allowed strange action
492 at a distance like rewriting a pending exception in C<$@>. Plans to
493 rectify this have been scrapped, as users found that rewriting a
494 pending exception is actually a useful feature, and not a bug.
495
496 Perl never issued a deprecation warning for this; the deprecation
497 was by documentation policy only. But this deprecation has been 
498 lifted as of Perl 5.26.
499
500
501 =head3 Malformed UTF-8 string in "%s"
502
503 This message indicates a bug either in the Perl core or in XS
504 code. Such code was trying to find out if a character, allegedly
505 stored internally encoded as UTF-8, was of a given type, such as
506 being punctuation or a digit.  But the character was not encoded
507 in legal UTF-8.  The C<%s> is replaced by a string that can be used
508 by knowledgeable people to determine what the type being checked
509 against was.
510
511 Passing malformed strings was deprecated in Perl 5.18, and
512 became fatal in Perl 5.26.
513
514
515 =head2 Perl 5.24
516
517 =head3 Use of C<< *glob{FILEHANDLE} >>
518
519 The use of C<< *glob{FILEHANDLE} >> was deprecated in Perl 5.8.
520 The intention was to use C<< *glob{IO} >> instead, for which 
521 C<< *glob{FILEHANDLE} >> is an alias.
522
523 However, this feature was undeprecated in Perl 5.24.
524
525 =head3 Calling POSIX::%s() is deprecated
526
527 The following functions in the C<POSIX> module are no longer available:
528 C<isalnum>, C<isalpha>, C<iscntrl>, C<isdigit>, C<isgraph>, C<islower>,  
529 C<isprint>, C<ispunct>, C<isspace>, C<isupper>, and C<isxdigit>.  The 
530 functions are buggy and don't work on UTF-8 encoded strings.  See their
531 entries in L<POSIX> for more information.
532
533 The functions were deprecated in Perl 5.20, and removed in Perl 5.24.
534
535
536 =head2 Perl 5.16
537
538 =head3 Use of %s on a handle without * is deprecated
539
540 It used to be possible to use C<tie>, C<tied> or C<untie> on a scalar
541 while the scalar holds a typeglob. This caused its filehandle to be
542 tied. It left no way to tie the scalar itself when it held a typeglob,
543 and no way to untie a scalar that had had a typeglob assigned to it.
544
545 This was deprecated in Perl 5.14, and the bug was fixed in Perl 5.16.
546
547 So now C<tie $scalar> will always tie the scalar, not the handle it holds.
548 To tie the handle, use C<tie *$scalar> (with an explicit asterisk).  The same
549 applies to C<tied *$scalar> and C<untie *$scalar>.
550
551
552 =head1 SEE ALSO
553
554 L<warnings>, L<diagnostics>.
555
556 =cut