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