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