1experimental(3) User Contributed Perl Documentation experimental(3)
2
3
4
6 experimental - Experimental features made easy
7
9 version 0.027
10
12 use experimental 'lexical_subs', 'signatures';
13 my sub plus_one($value) { $value + 1 }
14
16 This pragma provides an easy and convenient way to enable or disable
17 experimental features.
18
19 Every version of perl has some number of features present but
20 considered "experimental." For much of the life of Perl 5, this was
21 only a designation found in the documentation. Starting in Perl
22 v5.10.0, and more aggressively in v5.18.0, experimental features were
23 placed behind pragmata used to enable the feature and disable
24 associated warnings.
25
26 The "experimental" pragma exists to combine the required incantations
27 into a single interface stable across releases of perl. For every
28 experimental feature, this should enable the feature and silence
29 warnings for the enclosing lexical scope:
30
31 use experimental 'feature-name';
32
33 To disable the feature and, if applicable, re-enable any warnings, use:
34
35 no experimental 'feature-name';
36
37 The supported features, documented further below, are:
38
39 • "args_array_with_signatures" - allow @_ to be used in signatured
40 subs.
41
42 This is supported on perl 5.20.0 and above, but is likely to be
43 removed in the future.
44
45 • "array_base" - allow the use of $[ to change the starting index of
46 @array.
47
48 This was removed in perl 5.30.0.
49
50 • "autoderef" - allow push, each, keys, and other built-ins on
51 references.
52
53 This was added in perl 5.14.0 and removed in perl 5.24.0.
54
55 • "bitwise" - allow the new stringwise bit operators
56
57 This was added in perl 5.22.0.
58
59 • "builtin" - allow the use of the functions in the builtin::
60 namespace
61
62 This was added in perl 5.36.0
63
64 • "const_attr" - allow the :const attribute on subs
65
66 This was added in perl 5.22.0.
67
68 • "declared_refs" - enables aliasing via assignment to references
69
70 This was added in perl 5.26.0.
71
72 • "defer" - enables the use of defer blocks
73
74 This was added in perl 5.36.0
75
76 • "for_list" - allows iterating over multiple values at a time with
77 "for"
78
79 This was added in perl 5.36.0
80
81 • "isa" - allow the use of the "isa" infix operator
82
83 This was added in perl 5.32.0.
84
85 • "lexical_topic" - allow the use of lexical $_ via "my $_".
86
87 This was added in perl 5.10.0 and removed in perl 5.24.0.
88
89 • "lexical_subs" - allow the use of lexical subroutines.
90
91 This was added in 5.18.0.
92
93 • "postderef" - allow the use of postfix dereferencing expressions
94
95 This was added in perl 5.20.0, and became non-experimental (and
96 always enabled) in 5.24.0.
97
98 • "postderef_qq" - allow the use of postfix dereferencing expressions
99 inside interpolating strings
100
101 This was added in perl 5.20.0, and became non-experimental (and
102 always enabled) in 5.24.0.
103
104 • "re_strict" - enables strict mode in regular expressions
105
106 This was added in perl 5.22.0.
107
108 • "refaliasing" - allow aliasing via "\$x = \$y"
109
110 This was added in perl 5.22.0.
111
112 • "regex_sets" - allow extended bracketed character classes in
113 regexps
114
115 This was added in perl 5.18.0.
116
117 • "signatures" - allow subroutine signatures (for named arguments)
118
119 This was added in perl 5.20.0.
120
121 • "smartmatch" - allow the use of "~~"
122
123 This was added in perl 5.10.0, but it should be noted there are
124 significant incompatibilities between 5.10.0 and 5.10.1.
125
126 • "switch" - allow the use of "~~", given, and when
127
128 This was added in perl 5.10.0.
129
130 • "try" - allow the use of "try" and "catch"
131
132 This was added in perl 5.34.0
133
134 • "win32_perlio" - allows the use of the :win32 IO layer.
135
136 This was added on perl 5.22.0.
137
138 Ordering matters
139 Using this pragma to 'enable an experimental feature' is another way of
140 saying that this pragma will disable the warnings which would result
141 from using that feature. Therefore, the order in which pragmas are
142 applied is important. In particular, you probably want to enable
143 experimental features after you enable warnings:
144
145 use warnings;
146 use experimental 'smartmatch';
147
148 You also need to take care with modules that enable warnings for you.
149 A common example being Moose. In this example, warnings for the
150 'smartmatch' feature are first turned on by the warnings pragma, off by
151 the experimental pragma and back on again by the Moose module (fix is
152 to switch the last two lines):
153
154 use warnings;
155 use experimental 'smartmatch';
156 use Moose;
157
158 Disclaimer
159 Because of the nature of the features it enables, forward compatibility
160 can not be guaranteed in any way.
161
163 perlexperiment contains more information about experimental features.
164
166 Leon Timmermans <leont@cpan.org>
167
169 This software is copyright (c) 2013 by Leon Timmermans.
170
171 This is free software; you can redistribute it and/or modify it under
172 the same terms as the Perl 5 programming language system itself.
173
174
175
176perl v5.34.0 2022-02-09 experimental(3)