3 perldeprecation - list Perl deprecations
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.
11 This document will try to discuss what alternatives for the deprecated
12 features are available.
14 The deprecated features will be grouped by the version of Perl in
15 which they will be removed.
19 =head3 Constants from lexical variables potentially modified elsewhere
21 You wrote something like
24 $sub = sub () { $var };
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.
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.
38 If you intended for the subroutine to be eligible for inlining, then
39 make sure the variable is not referenced elsewhere, possibly by
43 $sub = sub () { $var2 };
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>:
49 $sub = sub () { return $var };
51 This usage has been deprecated, and will no longer be allowed in Perl 5.32.
53 =head3 Use of strings with code points over 0xFF as arguments to C<vec>
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.
59 =head3 Use of code points over 0xFF in string bitwise operators
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.
74 The wide character is not used in the C<&> operation because the left
75 operand is shorter. This now warns anyway.
77 =head3 hostname() doesn't accept any arguments
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
87 =head3 Unescaped left braces in regular expressions
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,
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. A non-deprecation
104 warning that the left brace is being taken literally is raised in
105 contexts where there could be confusion about it.
107 Literal uses of C<{> were deprecated in Perl 5.20, and some uses of it
108 started to give deprecation warnings since. These cases were made fatal
109 in Perl 5.26. Due to an oversight, not all cases of a use of a literal
110 C<{> got a deprecation warning. Some cases started warning in Perl 5.26,
111 and were made fatal in Perl 5.30. Other cases started in Perl 5.28,
112 and will be made fatal in 5.32.
116 =head3 C<< $* >> is no longer supported
118 Before Perl 5.10, setting C<< $* >> to a true value globally enabled
119 multi-line matching within a string. This relique from the past lost
120 its special meaning in 5.10. Use of this variable will be a fatal error
121 in Perl 5.30, freeing the variable up for a future special meaning.
123 To enable multiline matching one should use the C<< /m >> regexp
124 modifier (possibly in combination with C<< /s >>). This can be set
125 on a per match bases, or can be enabled per lexical scope (including
126 a whole file) with C<< use re '/m' >>.
128 =head3 C<< $# >> is no longer supported
130 This variable used to have a special meaning -- it could be used
131 to control how numbers were formatted when printed. This seldom
132 used functionality was removed in Perl 5.10. In order to free up
133 the variable for a future special meaning, its use will be a fatal
136 To specify how numbers are formatted when printed, one is advised
137 to use C<< printf >> or C<< sprintf >> instead.
139 =head3 Assigning non-zero to C<< $[ >> is fatal
141 This variable (and the corresponding C<array_base> feature and
142 L<arybase> module) allowed changing the base for array and string
145 Setting this to a non-zero value has been deprecated since Perl 5.12 and
146 throws a fatal error as of Perl 5.30.
148 =head3 C<< File::Glob::glob() >> will disappear
150 C<< File::Glob >> has a function called C<< glob >>, which just calls
151 C<< bsd_glob >>. However, its prototype is different from the prototype
152 of C<< CORE::glob >>, and hence, C<< File::Glob::glob >> should not
155 C<< File::Glob::glob() >> was deprecated in Perl 5.8. A deprecation
156 message was issued from Perl 5.26 onwards, and the function will
157 disappear in Perl 5.30.
159 Code using C<< File::Glob::glob() >> should call
160 C<< File::Glob::bsd_glob() >> instead.
162 =head3 Unescaped left braces in regular expressions (for 5.30)
164 See L</Unescaped left braces in regular expressions> above.
166 =head3 Unqualified C<dump()>
168 Use of C<dump()> instead of C<CORE::dump()> was deprecated in Perl 5.8,
169 and an unqualified C<dump()> will no longer be available in Perl 5.30.
171 See L<perlfunc/dump>.
174 =head3 Using my() in false conditional.
176 There has been a long-standing bug in Perl that causes a lexical variable
177 not to be cleared at scope exit when its declaration includes a false
178 conditional. Some people have exploited this bug to achieve a kind of
179 static variable. Since we intend to fix this bug, we don't want people
180 relying on this behavior.
182 Instead, it's recommended one uses C<state> variables to achieve the
186 sub count {state $counter; return ++ $counter}
187 say count (); # Prints 1
188 say count (); # Prints 2
190 C<state> variables were introduced in Perl 5.10.
192 Alternatively, you can achieve a similar static effect by
193 declaring the variable in a separate block outside the function, eg
195 sub f { my $x if 0; return $x++ }
199 { my $x; sub f { return $x++ } }
201 The use of C<my()> in a false conditional has been deprecated in
202 Perl 5.10, and it will become a fatal error in Perl 5.30.
205 =head3 Reading/writing bytes from/to :utf8 handles.
207 The sysread(), recv(), syswrite() and send() operators are
208 deprecated on handles that have the C<:utf8> layer, either explicitly, or
209 implicitly, eg., with the C<:encoding(UTF-16LE)> layer.
211 Both sysread() and recv() currently use only the C<:utf8> flag for the stream,
212 ignoring the actual layers. Since sysread() and recv() do no UTF-8
213 validation they can end up creating invalidly encoded scalars.
215 Similarly, syswrite() and send() use only the C<:utf8> flag, otherwise ignoring
216 any layers. If the flag is set, both write the value UTF-8 encoded, even if
217 the layer is some different encoding, such as the example above.
219 Ideally, all of these operators would completely ignore the C<:utf8> state,
220 working only with bytes, but this would result in silently breaking existing
221 code. To avoid this a future version of perl will throw an exception when
222 any of sysread(), recv(), syswrite() or send() are called on handle with the
225 In Perl 5.30, it will no longer be possible to use sysread(), recv(),
226 syswrite() or send() to read or send bytes from/to :utf8 handles.
229 =head3 Use of unassigned code point or non-standalone grapheme for a delimiter.
231 A grapheme is what appears to a native-speaker of a language to be a
232 character. In Unicode (and hence Perl) a grapheme may actually be
233 several adjacent characters that together form a complete grapheme. For
234 example, there can be a base character, like "R" and an accent, like a
235 circumflex "^", that appear to be a single character when displayed,
236 with the circumflex hovering over the "R".
238 As of Perl 5.30, use of delimiters which are non-standalone graphemes is
239 fatal, in order to move the language to be able to accept
240 multi-character graphemes as delimiters.
242 Also, as of Perl 5.30, delimiters which are unassigned code points
243 but that may someday become assigned are prohibited. Otherwise, code
244 that works today would fail to compile if the currently unassigned
245 delimiter ends up being something that isn't a stand-alone grapheme.
246 Because Unicode is never going to assign L<non-character code
247 points|perlunicode/Noncharacter code points>, nor L<code points that are
248 above the legal Unicode maximum|perlunicode/Beyond Unicode code
249 points>, those can be delimiters.
251 =head3 In XS code, use of various macros dealing with UTF-8.
253 These macros will require an extra parameter in Perl 5.30:
254 C<isALPHANUMERIC_utf8>,
265 C<isALPHANUMERIC_LC_utf8>,
273 C<isIDFIRST_LC_utf8>,
280 C<isWORDCHAR_LC_utf8>,
288 There is now a macro that corresponds to each one of these, simply by
289 appending C<_safe> to the name. It takes the extra parameter.
290 For example, C<isDIGIT_utf8_safe> corresponds to C<isDIGIT_utf8>, but
291 takes the extra parameter, and its use doesn't generate a deprecation
292 warning. All are documented in L<perlapi/Character case changing> and
293 L<perlapi/Character classification>.
295 You can change to use these versions at any time, or, if you can live
296 with the deprecation messages, wait until 5.30 and add the parameter to
297 the existing calls, without changing the names.
301 =head3 Attributes C<< :locked >> and C<< :unique >>
303 The attributes C<< :locked >> (on code references) and C<< :unique >>
304 (on array, hash and scalar references) have had no effect since
305 Perl 5.005 and Perl 5.8.8 respectively. Their use has been deprecated
308 As of Perl 5.28, these attributes are syntax errors. Since the
309 attributes do not do anything, removing them from your code fixes
310 the syntax error; and removing them will not influence the behaviour
314 =head3 Bare here-document terminators
316 Perl has allowed you to use a bare here-document terminator to have the
317 here-document end at the first empty line. This practise was deprecated
318 in Perl 5.000; as of Perl 5.28, using a bare here-document terminator
319 throws a fatal error.
321 You are encouraged to use the explicitly quoted form if you wish to
322 use an empty line as the terminator of the here-document:
327 # Previous blank line ends the here-document.
330 =head3 Setting $/ to a reference to a non-positive integer
332 You assigned a reference to a scalar to C<$/> where the
333 referenced item is not a positive integer. In older perls this B<appeared>
334 to work the same as setting it to C<undef> but was in fact internally
335 different, less efficient and with very bad luck could have resulted in
336 your file being split by a stringified form of the reference.
338 In Perl 5.20.0 this was changed so that it would be B<exactly> the same as
339 setting C<$/> to undef, with the exception that this warning would be
342 As of Perl 5.28, setting C<$/> to a reference of a non-positive
343 integer throws a fatal error.
345 You are recommended to change your code to set C<$/> to C<undef> explicitly
346 if you wish to slurp the file.
349 =head3 Limit on the value of Unicode code points.
351 Unicode only allows code points up to 0x10FFFF, but Perl allows
352 much larger ones. Up till Perl 5.28, it was allowed to use code
353 points exceeding the maximum value of an integer (C<IV_MAX>).
354 However, that did break the perl interpreter in some constructs,
355 including causing it to hang in a few cases. The known problem
356 areas were in C<tr///>, regular expression pattern matching using
357 quantifiers, as quote delimiters in C<qI<X>...I<X>> (where I<X> is
358 the C<chr()> of a large code point), and as the upper limits in
361 The use of out of range code points was deprecated in Perl 5.24; as of
362 Perl 5.28 using a code point exceeding C<IV_MAX> throws a fatal error.
364 If your code is to run on various platforms, keep in mind that the upper
365 limit depends on the platform. It is much larger on 64-bit word sizes
366 than 32-bit ones. For 32-bit integers, C<IV_MAX> equals C<0x7FFFFFFF>,
367 for 64-bit integers, C<IV_MAX> equals C<0x7FFFFFFFFFFFFFFF>.
370 =head3 Use of comma-less variable list in formats.
372 It was allowed to use a list of variables in a format, without
373 separating them with commas. This usage has been deprecated
374 for a long time, and as of Perl 5.28, this throws a fatal error.
376 =head3 Use of C<\N{}>
378 Use of C<\N{}> with nothing between the braces was deprecated in
379 Perl 5.24, and throws a fatal error as of Perl 5.28.
381 Since such a construct is equivalent to using an empty string,
382 you are recommended to remove such C<\N{}> constructs.
384 =head3 Using the same symbol to open a filehandle and a dirhandle
386 It used to be legal to use C<open()> to associate both a
387 filehandle and a dirhandle to the same symbol (glob or scalar).
388 This idiom is likely to be confusing, and it was deprecated in
391 Using the same symbol to C<open()> a filehandle and a dirhandle
392 throws a fatal error as of Perl 5.28.
394 You should be using two different symbols instead.
396 =head3 ${^ENCODING} is no longer supported.
398 The special variable C<${^ENCODING}> was used to implement
399 the C<encoding> pragma. Setting this variable to anything other
400 than C<undef> was deprecated in Perl 5.22. Full deprecation
401 of the variable happened in Perl 5.25.3.
403 Setting this variable to anything other than an undefined value
404 throws a fatal error as of Perl 5.28.
407 =head3 C<< B::OP::terse >>
409 This method, which just calls C<< B::Concise::b_terse >>, has been
410 deprecated, and disappeared in Perl 5.28. Please use
411 C<< B::Concise >> instead.
415 =head3 Use of inherited AUTOLOAD for non-method %s::%s() is no longer allowed
417 As an (ahem) accidental feature, C<AUTOLOAD> subroutines were looked
418 up as methods (using the C<@ISA> hierarchy) even when the subroutines
419 to be autoloaded were called as plain functions (e.g. C<Foo::bar()>),
420 not as methods (e.g. C<< Foo->bar() >> or C<< $obj->bar() >>).
422 This bug was deprecated in Perl 5.004, has been rectified in Perl 5.28
423 by using method lookup only for methods' C<AUTOLOAD>s.
425 The simple rule is: Inheritance will not work when autoloading
426 non-methods. The simple fix for old code is: In any module that used
427 to depend on inheriting C<AUTOLOAD> for non-methods from a base class
428 named C<BaseClass>, execute C<*AUTOLOAD = \&BaseClass::AUTOLOAD> during
431 In code that currently says C<use AutoLoader; @ISA = qw(AutoLoader);>
432 you should remove AutoLoader from @ISA and change C<use AutoLoader;> to
433 C<use AutoLoader 'AUTOLOAD';>.
436 =head3 Use of code points over 0xFF in string bitwise operators
438 The string bitwise operators, C<&>, C<|>, C<^>, and C<~>, treat
439 their operands as strings of bytes. As such, values above 0xFF
440 are nonsensical. Using such code points with these operators
441 was deprecated in Perl 5.24, and is fatal as of Perl 5.28.
443 =head3 In XS code, use of C<to_utf8_case()>
445 This function has been removed as of Perl 5.28; instead convert to call
446 the appropriate one of:
447 L<C<toFOLD_utf8_safe>|perlapi/toFOLD_utf8_safe>.
448 L<C<toLOWER_utf8_safe>|perlapi/toLOWER_utf8_safe>,
449 L<C<toTITLE_utf8_safe>|perlapi/toTITLE_utf8_safe>,
451 L<C<toUPPER_utf8_safe>|perlapi/toUPPER_utf8_safe>.
455 =head3 C<< --libpods >> in C<< Pod::Html >>
457 Since Perl 5.18, the option C<< --libpods >> has been deprecated, and
458 using this option did not do anything other than producing a warning.
460 The C<< --libpods >> option is no longer recognized as of Perl 5.26.
463 =head3 The utilities C<< c2ph >> and C<< pstruct >>
465 These old, perl3-era utilities have been deprecated in favour of
466 C<< h2xs >> for a long time. As of Perl 5.26, they have been removed.
469 =head3 Trapping C<< $SIG {__DIE__} >> other than during program exit.
471 The C<$SIG{__DIE__}> hook is called even inside an C<eval()>. It was
472 never intended to happen this way, but an implementation glitch made
473 this possible. This used to be deprecated, as it allowed strange action
474 at a distance like rewriting a pending exception in C<$@>. Plans to
475 rectify this have been scrapped, as users found that rewriting a
476 pending exception is actually a useful feature, and not a bug.
478 Perl never issued a deprecation warning for this; the deprecation
479 was by documentation policy only. But this deprecation has been
480 lifted as of Perl 5.26.
483 =head3 Malformed UTF-8 string in "%s"
485 This message indicates a bug either in the Perl core or in XS
486 code. Such code was trying to find out if a character, allegedly
487 stored internally encoded as UTF-8, was of a given type, such as
488 being punctuation or a digit. But the character was not encoded
489 in legal UTF-8. The C<%s> is replaced by a string that can be used
490 by knowledgeable people to determine what the type being checked
493 Passing malformed strings was deprecated in Perl 5.18, and
494 became fatal in Perl 5.26.
499 =head3 Use of C<< *glob{FILEHANDLE} >>
501 The use of C<< *glob{FILEHANDLE} >> was deprecated in Perl 5.8.
502 The intention was to use C<< *glob{IO} >> instead, for which
503 C<< *glob{FILEHANDLE} >> is an alias.
505 However, this feature was undeprecated in Perl 5.24.
507 =head3 Calling POSIX::%s() is deprecated
509 The following functions in the C<POSIX> module are no longer available:
510 C<isalnum>, C<isalpha>, C<iscntrl>, C<isdigit>, C<isgraph>, C<islower>,
511 C<isprint>, C<ispunct>, C<isspace>, C<isupper>, and C<isxdigit>. The
512 functions are buggy and don't work on UTF-8 encoded strings. See their
513 entries in L<POSIX> for more information.
515 The functions were deprecated in Perl 5.20, and removed in Perl 5.24.
520 =head3 Use of %s on a handle without * is deprecated
522 It used to be possible to use C<tie>, C<tied> or C<untie> on a scalar
523 while the scalar holds a typeglob. This caused its filehandle to be
524 tied. It left no way to tie the scalar itself when it held a typeglob,
525 and no way to untie a scalar that had had a typeglob assigned to it.
527 This was deprecated in Perl 5.14, and the bug was fixed in Perl 5.16.
529 So now C<tie $scalar> will always tie the scalar, not the handle it holds.
530 To tie the handle, use C<tie *$scalar> (with an explicit asterisk). The same
531 applies to C<tied *$scalar> and C<untie *$scalar>.
536 L<warnings>, L<diagnostics>.