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