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