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